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

learn more… | top users | synonyms (1)

2
votes
1answer
168 views

Lesser of two evils regarding return types

I'm implementing a system in PHP where values are represented with objects that implement an Amount interface. I'm building two different implementations of this interface, one using a simple integer ...
0
votes
0answers
69 views

Is using Interface implemented by single class a not recommended practice? [duplicate]

I have several classes in C#, not just POCO class but with methods and implementations. Each of those classes implement one Interface. e.g. IPerson implemented by Person class. Employee implements ...
5
votes
5answers
242 views

Does it always make sense to “program to an interface” in Java?

I've seen the discussion at this question regarding how a class that implements from an interface would be instantiated. In my case, I'm writing a very small program in Java that uses an instance of ...
26
votes
4answers
3k views

Why is .compareTo() in an interface while .equals() is in a class in Java?

I want to know why the .compareTo() is in the Comparable interface while a method like .equals is in the Object class. To me, it seems arbitrary why a method like .compareTo() is not in the Object ...
2
votes
2answers
60 views

Design interface for WebService to access several MySQL databases

I am currently trying to design an interface for a WebService that can access several MySQL databases. There will be 4 operations available, Add(), Read(), Update() and Delete(). The WebService just ...
2
votes
1answer
66 views

Application plugin system - interfaces - adding new features

Imagine I have an application, which have plugin system. public class MyPlugin : Plugin { public override ExecuteImpl (Context ctx) { // do something... } ...
0
votes
0answers
42 views

Class Interfaces with Multiple Classes and Dependency Injection

NOTE ON QUESTION TITLE: I did not really even know how to phrase the title so if someone can edit and make it more articulate I would really appreciate it. QUESTION: Basically, what I'm trying to do ...
4
votes
2answers
97 views

Is it considered good practice to declare base interfaces without mutators, supplying mutatators in a sub-interface

I asked a question on StackOverflow on how to properly implement an ImmutableMap that abides by the SOLID principles. Due to Java's Map interface containing put and putAll, it violates the interface ...
2
votes
3answers
125 views

Many different classes that need similar functionality. Best approach?

I have many (at the moment around 30) different message classes in an application I am creating. Each of these messages need to be serialized and deserialized. However, the process of serializing and ...
3
votes
0answers
94 views

License that encourages improvements to the original version rather than own forks? [closed]

I'm looking for a license that should encourage changes to my original open source rather than encouraging forks and uncontrolled random redistribution. This is because of the nature of the code; it's ...
3
votes
3answers
311 views

“One of some”-type

Say that you have some different classes that does not really have any functionality in common, but somewhere in your program, you need one of them (which one is not necessarily important) because ...
1
vote
4answers
191 views

When to make a method part of an interface or a concrete implementation? [duplicate]

I create an interface for database access to a MySQL database. Currently, this is the only way to access day, but to make it easier to test and in the event that the data access might change, I used ...
0
votes
1answer
90 views

Can you refer to the callback function as an API?

A system design is decoupled into two layers say layer A and layer B. The interaction between layer A and layer B occurs through an interface that is exposed by layer B in form of an API. This ...
5
votes
1answer
196 views

Sometimes, “programming to interfaces” introduces possible (and avoidable) runtime exceptions?

Please consider the com.google.common.collect.ImmutableMap Programming to its interface, Map , creates a bug that could blow-up in the runtime as such: Map<String, Integer> myMap = ...
16
votes
5answers
3k views

Do enums create brittle interfaces?

Consider the example below. Any change to the ColorChoice enum affects all IWindowColor subclasses. Do enums tend to cause brittle interfaces? Is there something better than an enum to allow for ...
2
votes
2answers
79 views

How do you maintain protocol of function return value in dynamic language?

In dynamic programming language like Python, Javascript, it's very easy to make a function return an object: def make_vector2(a, b): return {"x": a, "y": b} The 'signature' of the returned ...
2
votes
1answer
81 views

Is Dependency Inversion a valid alternative to the pImpl idiom?

If I want to present to the user of my code an interface, that is unlikely to change, I can write only the public part of the classes in public headers and have a single private pointer to another ...
0
votes
2answers
110 views

Should I extend an interface or keep it independent?

I'm trying to decide whether to extend a base interface with additional methods or create several independent interfaces. I have a Task interface that looks like this interface Task { public ...
2
votes
2answers
91 views

Delegating work and programming to component interfaces

I have a MessageHandler class which receives and validates messages before determining which components in the architecture they should be delegated to so they can be processed. This involves calling ...
8
votes
2answers
996 views

Is using interfaces for datatypes an anti-pattern?

Suppose I have a various entities in my model (using EF), say User, Product, Invoice and Order. I am writing a user control that can can print the summaries of entity objects in my application where ...
2
votes
5answers
223 views

Implement multiple separate interfaces or interface hierarchy

I've been refactoring one of my projects recently and ran into a decision I have to make. I have several interfaces: Entity: Something in the game world Actor: An Entity that can perform actions ...
2
votes
2answers
218 views

When to use a SortedMap interface?

The rule in programming is to use the most general interface possible. But the difference between Map and SortedMap is more subtle. They compile to the same bytecode [I think] No additional safety ...
2
votes
2answers
72 views

Are single method interface and function type definition the same?

In a language where it is possible to define interfaces and typedefs (using Dart here): abstract class Receiver { void receive(int quantity); } typedef void Receive(int quantity); abstract class ...
2
votes
2answers
66 views

Interface design - Parameter choice

Situation: Is it better to have one or few parameters that supply more than enough information for the intended process or should you have more specific parameters that provide just enough ...
1
vote
0answers
28 views

do my “dal” and “fileHandler” interfaces overlap?

I want my program to: 1) read some input lines from csv file 2) write the output lines to plain string file 3) read some input from the same file in (2) and compare it to some calculated data. I ...
0
votes
1answer
56 views

Implementing an interface already implemented by a parent class?

If a class extends a parent which defines an interface, should that class also explicitly implement the interface? As an example, is it better to include or remove the portion in square brackets ...
1
vote
1answer
59 views

Documentation of interfaces

I know how to document a function: /** * Prints a greet message to the web page */ function greet() { echo "Hi!"; } Or describe the usage of a variable: /** * @type string $name The user's ...
0
votes
4answers
228 views

How should nodes in a chain be connected?

Suppose you were building a system that receives data on one end and sends filtered data on the other end. The system is a chain of nodes, each receiving data from the node before and sending ...
0
votes
1answer
180 views

Interface or boolean?

I have a CustomObject class which has the abilities like being Clickable, KeyPressable and Movable. I created interfaces: IClickable, IKeyPressable and IMovable and make different CustomObject classes ...
5
votes
2answers
151 views

Is it good design to put abstract methods in an abstract class even though the methods are already defined in its interface?

Let's say we have an interface Foo with a method "public void someMethod()", and we have one or multiple abstract classes that "implement" Foo but don't necessarily themselves provide an ...
16
votes
4answers
2k views

Should a front-end developer ever specify JSON format for back-end developers?

I am taking the front-end role in a project. Should I be specifying for my back-end teammates the exact format of JSON that their PHP returns to my JavaScript? For example, should I be telling them ...
1
vote
0answers
73 views

How does one enforce the implementation of a static method? [duplicate]

Of course the answer to the question above is, "you can't". But I didn't have a better way of describing what I'm looking for. If I did, I wouldn't be asking this question. My problem stems from a C# ...
1
vote
0answers
37 views

Adding new Interface & Replacing Method with Interface Type

Let's say that I have 2 classes: Foo and Bar. `Foo` { List<Bar> bars String bippy() int boop() } `Bar` { int biz() String baz() } Observe that Foo's fields include a List<Bar>. ...
4
votes
3answers
288 views

Why use arg type `class Object` instead of `Comparable[]`?

In the code below, I believe it would look more appropriate to make the method argument be of type Comparable[] instead of Object[]. The first reason it would be more appropriate is that one can be ...
0
votes
2answers
182 views

Develop GUI and logic in a team the right way? [closed]

I am planning to start a small project with a friend. I will be developing the GUI using JavaFX in the MVC pattern and he will be responsible for the model/logic. My question is: how can we achieve a ...
0
votes
1answer
52 views

Interfaces between multiple projects

I'm slightly confused over the following: ProjectA -------- GetUsers (Implements IDBConnector) -------- IGetUsers -------- UserModel ProjectB -------- Main I have two projects one main project ...
1
vote
1answer
58 views

Do the implementations of the Node interface in Web API violate Liskov Substitution Principle?

MDN article on Node interface states that interfaces [that inherit from Node interface] may return null in particular cases where the methods and properties are not relevant. They may throw an ...
0
votes
1answer
111 views

Async properties in interfaces to cater for the possibility of expensive first-time evaluation: Is this a good idea?

First of all, sorry if this post is too long. I'll start with the… Short version: Is it generally advisable or a good idea to design an interface property as asynchronous simply because we cannot be ...
0
votes
4answers
1k views

Why 'List<E>' is an 'interface' but not 'abstract class'?

While defining the hierarchy, one can think to embed the abstract method(behaviour) in abstract class only because the derive concrete class posses that as core behaviour with it's specific ...
1
vote
2answers
359 views

Programming against interfaces in Java

Supposing I have an interface Foo and a given implementation FooImpl. public class FooImpl implements Foo If I want to define a new operation on this class that depends on the particular ...
1
vote
2answers
154 views

Cleanest choice for symmetric operations

I have a need to do some processing from a format A to a format B and from B to A. The job in one direction is very similar to its counterpart. Both formats are represented with an interface Msg. In ...
0
votes
0answers
30 views

Restructuring similar interfaces to one unified design

In my project, I have several types of Web API controllers (and their corresponding services and repositories). When I started out, I made an interface of a generic type that would describe the basic ...
11
votes
4answers
2k views

Is it permissible to use explicit interface implementation to hide members in C#?

I understand how to work with interfaces and explicit interface implementation in C#, but I was wondering if it's considered bad form to hide away certain members that would not be used frequently. ...
2
votes
4answers
224 views

Determining a class structure

I'm currently in the early stages of designing an e-commerce application. I'm working out some designs for my classes which have so far been fairly straightforward, but I've run into something of a ...
1
vote
3answers
255 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
94 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 ...
14
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 ...
3
votes
1answer
206 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
133 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
1k 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 ...