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

learn more… | top users | synonyms (1)

3
votes
0answers
84 views

Java 8: 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
86 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
0answers
13 views

How can I run external code from Squeak environment? [migrated]

As far as I know, the Squeak environment is quite isolated from the rest of the operating system. However, I'm looking for a way to execute external code, which will be written in a different ...
0
votes
2answers
72 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
163 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
24 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 ...
-2
votes
0answers
50 views

When to to use which - Interface vs. Abstract Class? [duplicate]

This is a very common problem, when should I use Interface and when an abstract class. I know the theoretical differences between these two, but its still confusing for me to decide upon when should I ...
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
72 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
115 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; ...
2
votes
0answers
47 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
188 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
141 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
93 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
447 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
94 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
342 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
118 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
124 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
476 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
246 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
293 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
467 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
88 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
239 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
68 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
69 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
147 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
120 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
145 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
272 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
145 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
126 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
276 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
134 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
763 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
120 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
186 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
173 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
145 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 ...
0
votes
2answers
98 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 ...
1
vote
2answers
272 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 ...
0
votes
1answer
107 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
96 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
180 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 ...
2
votes
2answers
116 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 ...