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

learn more… | top users | synonyms (1)

0
votes
2answers
72 views

Implements > extends, but what about variables?

It's preferable to write programs that depend on interfaces rather than on superclasses, but what when you want a class to have certain variables? Sometimes you want a class to implement a certain ...
0
votes
1answer
79 views

when would you wrap a service object with an interface? [duplicate]

I'm new to UT and some of the best practices and anti-patterns when writing testable code, made me think. I used to wrap any service object with interface. but I see many mocking frameworks can ...
12
votes
2answers
2k views

Illegal in PHP: Is there an OOP design reason?

The below interface inheritance is illegal in PHP, but I think it would be fairly useful in real life. Is there an actual antipattern or documented problem with the below design, that PHP is ...
2
votes
1answer
110 views

Trying to get a better understanding of Interfaces

Im working on a small program and I thought i would use it as a chance to get a better understanding of things I haven't really used before, mainly Interfaces and Inheritance from base classes. ...
4
votes
1answer
78 views

Handling interface segregation in C++

I'm designing a "view" handling system for a game. The goal is to be able to have different "views" that can be shown in sequence or stacked on-top of each other. For example, the initial splash ...
3
votes
4answers
449 views

How to force “program to an interface” without using a java Interface in java 1.6

In java 1.8 they have wonderful new "default interface methods". In 1.6 how close can we come? The goal: keep clients (using code) from being able to tell that a class is not a java interface. If ...
0
votes
1answer
102 views

Static methods vs Interface implementation

Here is my problem: I stared to create a e-commerce web sites info collector. So i created a parser for each site. The parser class is state less. got methods like: getItemPrice(WebElement page) ...
3
votes
3answers
193 views

Should I denote that a method satisfies an interface?

When writing a class which has ("satisfies") 1 or more interfaces, should I note somehow (e.g. in an XML comment, or with an attribute) that a particular method was added for one of the interfaces? ...
0
votes
1answer
32 views

Android, using a Fragment to hold/edit complex object, accesible from any Activity

I'll do my best to describe the problem, but I'm still very new to several concepts that I think this problem requires to be solved (namely interfaces and threads). I should preface this by saying ...
0
votes
2answers
133 views

How to organise and label methods, intended for debug?

I have a class System, which uses a bunch of other classes, to achieve a complex signal processing. In debugging System, one needs to observe the output signal for patterns. This is not achievable by ...
5
votes
3answers
208 views

Does it make sense to split up an existing multi-method interface into several single method interfaces just to take advantage of lambdas?

Say I have an existing callback interface that has multiple methods. To illustrate my point I use a callback the likes that you would see in code that performs some HTTP client operations: public ...
0
votes
0answers
101 views

How far to go when future proofing fluent-method-chained-DSL test code?

Is it worth implementing interfaces, or using the getThis() trick, or even static factory methods to future proof against the need to extend this DSL? The current design is a pair of thin ...
0
votes
2answers
74 views

Possible design patterns for base function with possible additions

I have various interfaces i have to implement. Let's assume ITypeA, ITypeB. They have following methods: ITypeA Connect Disconnect GetData SetData ClearData ITypeB Connect Disconnect ...
3
votes
2answers
175 views

Are there alternatives to using an optional type in a multithreaded environment?

I'm making an MPMC queue in C++, and I would like to find out what the best interface for a try_dequeue method would be (I'm not concerned about its implementation). I'd like to provide a method which ...
0
votes
0answers
33 views

Pitfalls of combining dependant traits and exceptions in same file as interface in php

What are the potential pitfalls of combining related class like objects (interfaces, traits, custom exceptions) in the same source file? For code reuse and only loading what I need I always separate ...
23
votes
9answers
2k views

Interface design where functions need to be called in a specific sequence

The task is to configure a piece of hardware within the device, according to some input specification. This should be achieved as follows: 1) Collect the configuration information. This can happen at ...
0
votes
1answer
74 views

Prepared statement alternatives for this middle-man program?

I have an program that is using a prepared statement to connect and write to a database working nicely, and now need to create a middle-man program to insert between this program and the database. ...
0
votes
1answer
120 views

How to generalize a classes that has identical function plus some additional function

I have some designing problems with my project. To illustrate my problem, I'll use the following two classes from my project. public class RAM_UserManagement{ private Map<int,User> userList; ...
3
votes
1answer
65 views

Traits, Inheritance and Interfaces in Groovy, when to use them?

I'm learning groovy and I've just learned about the new feature added in 2.3, which is the addition of Traits. Now to me it seems like Traits allow you to do basically everything a super-class and an ...
1
vote
3answers
198 views

Make Return Type an Interface - Problem with Initialization

I would like to make the return type of my method an interface rather than a class for similar reasons stated in c# List or IList, however I am having trouble figuring out how to initialize the ...
1
vote
4answers
153 views

Should I put extension methods of an interface in the interface.cs file?

Imagine this set up: public interface IMass{ double Mass {get;} } public static class IMassExtension { public static double ToKg(this IMass massObject) { return massObject.Mass / ...
2
votes
1answer
98 views

How modularized should my interfaces be?

I stumbled upon a specific instance where it seems that modularity and simplicity are at conflict with each other. Usually that's not the case, so I was really unsure how to resolve it. Suppose I ...
7
votes
4answers
469 views

“Immutable” interfaces

I am confused about the notion of immutability. Consider the following structure of a simplistic calculator: Here are the interfaces: interface IOperationalInterface { int Sum(int a, int b); } ...
1
vote
1answer
99 views

Domain-specific Interfaces

Are there any real benefits of using interfaces over abstract classes in a domain model? Does anyone have any experience using interfaces in a domain model in a real project? From a technical ...
4
votes
3answers
421 views

Why does C# allow properties in interfaces?

In C#, the following code is valid interface I{ int property{get;set;} } Which doesn't make any sense to me. This seems to break one of the most important principles of interfaces: lack of ...
1
vote
2answers
120 views

Should an abstract class always abstract its methods to an interface?

I had learned sometime ago that abstract classes should always abstract their functions to an interface. So instead of having something like this - abstract class a{ public int i; public int ...
4
votes
1answer
125 views

Designing module interfaces

I'm studying software engineering and one thing I'm really trying to improve is my skill in software architecture. My question is quite broad, so I'll try to explain it with an example. Suppose you ...
2
votes
2answers
251 views

Does it make sense to use interfaces if you don't have polymorphism?

Suppose I have distinct classes that have the same behavior, which can be represented like this: public interface Behavior { void operationA(); } public class ImplementerA implements Behavior { ...
1
vote
2answers
85 views

How specific should be an interface about its implementation details?

Perhaps I should have picked a better title, but anyway... Basically what to do with two or more implementations that have the same public interface, but they are meant for slightly different ...
3
votes
3answers
484 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] ...
39
votes
9answers
4k 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
283 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 ...
0
votes
3answers
298 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 ...
6
votes
4answers
471 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. ...
2
votes
0answers
97 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 ...
1
vote
4answers
262 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
73 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
70 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
153 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 ...
2
votes
2answers
122 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
1answer
100 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 ...
0
votes
2answers
148 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 ...
7
votes
2answers
275 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
2answers
152 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; } } ...
2
votes
1answer
139 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 ...
5
votes
5answers
317 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
135 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
815 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
129 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
193 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 ...