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

learn more… | top users | synonyms (1)

0
votes
4answers
685 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 ...
15
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
71 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# ...
0
votes
0answers
29 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
233 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
145 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
48 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 ...
0
votes
1answer
94 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 ...
2
votes
1answer
170 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 ...
3
votes
1answer
105 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
1answer
53 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
4answers
212 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
1answer
85 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 ...
2
votes
4answers
215 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 ...
8
votes
4answers
406 views

Use cases for “private” interfaces?

I was wondering if there was a valid use case for being able to properly define the specific internal properties and functions of a class in a way similar to how an interface defines the public ...
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 ...
4
votes
2answers
756 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 ...
1
vote
2answers
305 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 ...
5
votes
3answers
1k 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 ...
0
votes
3answers
143 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 ...
0
votes
0answers
27 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. ...
1
vote
3answers
229 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 ...
29
votes
9answers
4k 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? ...
0
votes
1answer
112 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
1answer
87 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 ...
2
votes
1answer
126 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. ...
3
votes
4answers
614 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 ...
4
votes
1answer
101 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
3answers
200 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
119 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) ...
0
votes
2answers
135 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
222 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
116 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 ...
12
votes
4answers
7k 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 ...
3
votes
2answers
186 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
2answers
79 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 ...
0
votes
0answers
56 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 ...
72
votes
14answers
19k views

Do I need to use an interface when only one class will ever implement it?

Isn't the whole point of an interface to for multiple classes to adhere to a set of rules and implementations?
23
votes
8answers
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
84 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
133 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; ...
10
votes
6answers
6k views

What are the differences between abstract classes, interfaces, and when to use them

Recently I have started to wrap my head around OOP, and I am now to the point where the more I read about the differences between abstract classes and interfaces the more confused I become. So far, ...
4
votes
1answer
131 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 ...
1
vote
3answers
250 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 ...
33
votes
4answers
15k views

Why should I prefer composition over inheritance?

I always read that composition is to be preferred over inheritance. A blog post on unlike minds, for example, advocates using composition over inheritance, but I can't see how polymorphism is ...
1
vote
4answers
214 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
104 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
478 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
112 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 ...