Questions tagged [interfaces]

Questions about interface related design considerations, and also "programming to the interface instead of the implementation"

Popular questions and answers

About the difference between "programming to an interface" (which might use Java/C#-style interfaces) and Java/C#-style interfaces:
External: Program to an interface not an Interface

725 questions
172
votes
19 answers

Why are interfaces useful?

I have been studying and coding in C# for some time now. But still, I can't figure the usefulness of Interfaces. They bring too little to the table. Other than providing the signatures of function, they do nothing. If I can remember the names and…
Pankaj Upadhyay
  • 5,070
  • 12
  • 44
  • 60
13
votes
4 answers

Two interfaces with identical signatures

I am attempting to model a card game where cards have two important sets of features: The first is an effect. These are the changes to the game state that happen when you play the card. The interface for effect is as follows: boolean…
corsiKa
  • 1,084
6
votes
9 answers

Does it make sense to declare private fields using an interface as their type?

For the fields that you have as encapsulated members of a class, does it make sense to declare their type to be of the interface that you are using? For example: public class PayrollInfo { private Map employees; public…
5
votes
2 answers

How to bring others to understand your interface

I'm working in a corporation that has two products. One is a desktop application the other is a web-application. I'm in on the part as backend-engineer on the web-application. I design the web-interfaces. We use SOAP as the interface technology. Now…
SWiggels
  • 169
  • 5
4
votes
7 answers

What problems will I face if I remove the concept of interfaces from my code?

I have been programming for many years but I am still not comfortable with the concept of "Interfaces". I try to use interfaces but many times I don't see a mandatory use for it. I think this is probably because the projects weren't so big, or…
Vishwas
  • 1,871
3
votes
1 answer

Heterogeneous interface hierarchy

I'm working on a program that tests a digital circuit. The digital circuit can process accesses from multiple different caches, CACHE0, CACHE1, etc. The digital circuit can handle accesses to different memories MEM0, MEM1, etc. and a special kind of…
Tudor Timi
  • 203
  • 2
  • 7
2
votes
3 answers

Adding Methods In Addition to an Interface

Let's say I have ThingImpl and IThing. The former is an implementation of the latter, which is an interface. IThing has 1 method: do(arg1) Is it considered a hack/bad practice to add a method in addition to do()? Example: do(arg1, arg2)
1
vote
1 answer

Use the chance to return booleans after method calls for an optional layer of exception handling?

I would like to ask a follow-up to a question I just asked: Better to have 2 methods with clear meaning, or just 1 dual use method? I now understand why it is best to separate charge(float c); and getBalance();. But, every method has the opportunity…
david.t
  • 437
1
vote
3 answers

Necessity of Interfaces for Small Projects

Is it necessary to use interfaces for small projects? I work at a shop writing small custom applications for clients, primarily data manipulation. I'm mostly self-taught but also took some programming classes in college. I've been trying to apply…
dprice
  • 67
  • 1
  • 1
  • 6
0
votes
2 answers

Where should I start using Interface only?

The more that I'm reading, the less I know about this one. I'm actually working on a new website using Symfony. In Symfony, you have the concept of Entity. An entity represent basically an object and discribe how this object should be stored into…
0
votes
1 answer

Are complex return types the answer to being able to depend on objects that implement said interface?

Assume I have an Ingest object that will only work with objects that implemented the MyInterface interface. The ingester takes all the said objects but our language does not have complex return types, as such, these objects, when implementing the…
coolpasta
  • 641
0
votes
1 answer

Should I separate the interface or use single one

I'm developing a game, I will generate objects. I have create an interface called IObject which has the following properties: String tag // Tag for the object Vector3 position // Where the element is positioned Mesh mesh // This is how the object…