Questions about interface related design considerations, such as programming to the interface.

learn more… | top users | synonyms (1)

0
votes
0answers
103 views

Inheritance vs interface

I know that this isn't new question, and even few (but far more specific) similar ones were asked here. But I want to ask you something in general meaning, not relating to any concrete case. Few days ...
34
votes
8answers
3k views

Programming for future use of interfaces

I have a colleague sitting next to me who designed an interface like this: public interface IEventGetter { public List<FooType> getFooList(String fooName, Date start, Date end) ...
2
votes
2answers
281 views

Why not apply Interface Segregation Principle to “extreme”

Providing that clients would typically consume just one method, though methods would be conceptually related, why not always apply the Interface Segregation Principle to the extreme and have [many] ...
2
votes
0answers
64 views

The inheritance argument of zope.interface (providedby vs isinstance)

What limitations does inheritance of an interface through an abstract base class present that are addressed by zope.interface? In the following talk given in 2010 by Jeff Rush about interfaces, at ...
2
votes
1answer
90 views

Interface hierarchy design for separate domains

There are businesses and people. People could be liked and businesses could be commented on: class Like class Comment class Person implements iLikeTarget class Business implements iCommentTarget ...
2
votes
1answer
142 views

Code re-use in C++, via multiple inheritance or composition? Or…?

I originally asked this question on StackOverflow, but I was directed here, and I think my problem is perhaps as much conceptual as technical, so here goes. If you’re defining a hierarchy of abstract ...
6
votes
4answers
444 views

Split up large interfaces

I'm using a large interface with about 50 methods to access a database. The interface has been written by a colleague of mine. We discussed this: Me: 50 methods is too much. It's a code smell. ...
0
votes
3answers
269 views

Why do APIs generally consist of interfaces? [duplicate]

I am starting out in Java API design and in reading existing code bases, I have found that most APIs consist of interfaces only with their implementations bundled in a different package. Having read ...
0
votes
1answer
313 views

Does it make sense to break fluid interface if a bad argument is passed?

If I chain some setters together and one of them does not return $this, then I will get a fatal error. But maybe that is a good thing. $object = new object(); ...
6
votes
1answer
219 views

How to hide AOP implementation dependency without breaking encapsulation?

I have the concept of a SlowLoading thing: public interface SlowLoading { boolean hasLoaded(); } I also have a component MyComponent: public interface myComponent{ void doSomething(); } My ...
0
votes
1answer
85 views

Naming interfaces for persistent values

I have 2 distinct types of persistent values that I'm having trouble naming well. They're defined with the following Java-esque structure, borrowing Guava's Optional for the example and using generic ...
79
votes
19answers
32k views

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, ...
1
vote
2answers
252 views

Go-like interfaces + multi-methods make sense?

Thinking about the design of a potential new language, I wonder how related are the concepts of built a OO similar to GO interfaces and multi-methods (I get this from ...
1
vote
4answers
215 views

Combinatorial explosion of interfaces: How many is too many?

I'm a relative newcomer to OOP, and I'm having a bit of trouble creating good designs when it comes to interfaces. Consider a class A with N public methods. There are a number of other classes, B, C, ...
1
vote
2answers
65 views

Creating an Interface To a Language's Standard Library?

In the process of learning test-driven development, I've been introduced to dependency injection and the use of interfaces, and have started using these concepts in my own PHP code in order to make it ...
5
votes
1answer
67 views

Designing communications for extensibility

I am working on the design stages of an application that will a) collect data from various sources (in my case that's scientific data from serial ports), keeping track of the age of the data, b) ...
0
votes
2answers
127 views

Java best practice Interface - subclasses and constants

In the case where a couple of classes implements an interface, and those classes have a couple of constants in common (but no functions), were should I put this constant ? I've had this problem a ...
3
votes
4answers
2k views

What are good reasons to use explicit interface implementation for the sole purpose of hiding members?

During one of my studies into the intricacies of C#, I came across an interesting passage concerning explicit interface implementation. While this syntax is quite helpful when you need to resolve ...
2
votes
2answers
114 views

Design for an interface implementation that provides additional functionality

There is a design problem that I came upon while implementing an interface: Let's say there is a Device interface that promises to provide functionalities PerformA() and GetB(). This interface will ...
0
votes
2answers
84 views

UML Class Diagram: Abstract or Interface?

I am modeling a class diagram and have spotted an opportunity to simplify it slightly. What I want to know is, would this it be better to implement an abstract class or an interface? The scenario is ...
0
votes
1answer
96 views

Should interface only be used for behavior and not to show logical data grouped together? [duplicate]

Should an interface only be used to specify certain behavior? Would it be wrong to use interface to group logically related data? To me it looks like we should not use interface to group logically ...
4
votes
4answers
715 views

Which methods should be put in an interface and which in abstract classes?

I have seen many frameworks and modules and their standard they follow is like this UserInterface which have some predefined methods AbstractUserClass which implements userInterface Then ...
0
votes
2answers
132 views

c# naming - What are common conventions for a suffix to distinguish between read-only and writable interfaces [closed]

Assume an interface that allows queries on a spatial tree public ISpatialTree { int FindChildIndex(Vector point); bool IsLeaf { get; } ICollection<ISpatialTree> Children { get; } } ...
0
votes
2answers
134 views

Is using interfaces on internal code a good idea? [duplicate]

I'm working on a set of automated tests that we use internally at work. Lately, we've been designing classes that implement interfaces in addition to inheritance. As I understand it, interfaces in ...
24
votes
9answers
3k views

Are abstract classes / methods obsolete?

I used to create a lot of abstract classes / methods. Then I started using interfaces. Now I am not sure if interfaces aren't making abstract classes obsolete. You need a fully abstract class? ...
2
votes
2answers
108 views

Segregating interfaces/concerns to a tree

When working with a single object there are a number of ways to segregate interfaces to it. Breaking it into smaller components that can be treated independently. Breaking it into simpler ...
5
votes
5answers
219 views

How to enforce implementation of interface to behave a certain way

Suppose you had the following interface public interface IUserRepository { User GetByID(int userID); } How would you enforce implementers of this interface to throw an exception if a user is ...
0
votes
2answers
128 views

Interface method signature not restrictive enough

I wrote a piece of code at my job sometime ago. While writting the code I wrote few interfaces who would allow me to add more flexibility and at that time I was also trying to understand OOP concept ...
13
votes
3answers
627 views

Why are interfaces more helpful than superclasses in achieving loose coupling?

(For the purpose of this question, when I say 'interface' I mean the language construct interface, and not an 'interface' in the other sense of the word, i.e. the public methods a class offers the ...
3
votes
1answer
101 views

Different scoring algorithms for different competition elements

I am creating a scoring system for a competition that is somewhat obscure, but it resembles the Olympics in terms of its high-level structure. Therefore, I will ask my question in terms of an ...
3
votes
2answers
157 views

How to manage memory in C interface for C++ implementation considering c++11?

I have a library implemented in C++ which has a C interface. This C interface is, for all intents and purposes, the only way to use this library. C++11 seems to discourage the use of raw pointers but ...
1
vote
1answer
158 views

Should I use inheritance or an interface?

So in a nutshell I have an abstract class : public abstract class Member { public string PCode { get; set; } public string Reference { get; set; } public DateTime? ElectedDate { get; set; } } And ...
1
vote
3answers
124 views

Empty superclass for Collection of derived classes

Basically, what I would like to obtain is a way to iterate through ONE list, and call methods specific to the interface the objects in the collection implement. In my Java project, it would result in ...
30
votes
6answers
3k views

Should interface names begin with an “I” prefix?

I have been reading "Clean Code" by Robert Martin to hopefully, become a better programmer. While none of it so far has been really ground breaking it has made me think differently about the way I ...
0
votes
2answers
113 views

Using interfaces as part of encapsulation

I'm creating interfaces for a number of our existing classes for mocking reasons. Many of these classes also have package scope methods as an attempt to give some level of encapsulation by ensuring ...
0
votes
1answer
93 views

When is it suitable to use inheritance [duplicate]

I recently had a small "argument" about inheritance with a friend. I think people overuse it a lot. Intuition tells me that that the only good reason for class inheritance is polymorphism - when there ...
0
votes
1answer
91 views

Can a Java interface declaration enforce parameter properties?

As far as I know, declaring an interface is like so: public interface Roots_Squares { public double square_root( double value ); } Now... how do you enforce value to have non-negative values? ...
0
votes
3answers
178 views

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 ...
1
vote
3answers
239 views

Why are inheritance and interfaces restricted to instance members?

Disclaimer: I think the rules are almost the same in most OO languages, but since I'm most familiar with C# I'll be relating to this specific language. I think that the use of attributes and ...
0
votes
3answers
131 views

Is declaring STL variables in a class definition too revealing?

If you are trying to hide implementation, would declaring STL variables be too revealing? // in Word_Bucket.h class Word_Bucket { private: std::vector<std::string> contents; ...etc } ...
0
votes
1answer
149 views

How to use namespaces to separate interface from implementation, in c++?

As far as I can tell, you can make your interface known to others by providing your .h file. Your .cpp is the implementation. Then they can see the function names, the parameter types, the return ...
3
votes
2answers
307 views

Implementing the Interface Segregation Principle

Does this IConvertible interface satisfy the Interface Segregation Principle (ie. the "I" in SOLID)? Here is the definition: public interface IConvertible { TypeCode GetTypeCode(); bool ...
45
votes
10answers
5k views

Is better Show() + Hide() or SetVisible(bool visible)?

What is better and why? (From interface-design point of view) : a) To have two Show() and Hide() functions b) To have one SetVisible(bool visible) function EDIT: For example some object have ...
0
votes
1answer
51 views

Inverse of Extract Interface refactoring

I'm working with a Java project that has several interfaces, many of which have only one implementation. (See related question) For a given revision of the software, one could think this acceptable ...
0
votes
0answers
40 views

What should I do with too much interfaces needed for a dialog

Let me start by doing a small summary of the changes we did in our code in the last year. We have a software (VERY big) that is used to visualize multiples underground networks, enter data in the ...
3
votes
3answers
2k views

Why were default and static methods added to interfaces in Java 8 when we already had abstract classes?

In Java 8, interfaces can contain implemented methods, static methods, and the so-called "default" methods (which the implementing classes do not need to override). In my (probably naive) view, there ...
2
votes
4answers
297 views

Understanding “programming to an interface”

I have come across the term "programming to an interface instead of an implementation" a lot, and I think I kind of understand what it means. But I want to make sure I understand it's benefits and ...
-1
votes
3answers
206 views

Regarding interfaces of classes in OOP

When one says "a class' interface": Does he/she refer to all of the get and set methods - or do they refer only to the methods' signatures and return types, without the inner implementation of these ...
-4
votes
1answer
137 views

what is the main utility of Interface in real world programming (OOPS) [duplicate]

what is the main utility of Interface. we know that we can implement dynamic behavior using interface but i guess it is not only the utility. so i like to know when we have to write interface and when ...
12
votes
9answers
4k views

Default vs Impl when implementing interfaces in Java

After reading Should package names be singular or plural? it occurred to me that I've never seen a proper debate covering one of my pet peeves: naming implementations of interfaces. Let's assume ...