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

learn more… | top users | synonyms (1)

1
vote
1answer
398 views

JEE MVC, controller calls the interface instead of the interface implementation

I'm following this tutorial: http://wiki4.caucho.com/Building_a_simple_listing_in_JSP It creates a basic web application in Eclipse using the MVC pattern with Resin as the web container. Here's the ...
0
votes
0answers
127 views

What is the meaning of the different interface types in Ian Sommervilles's Software Engineering?

Reading Ian Sommervilles's Software engineering, he mentiones there are following interfaces: Paramater interface: data or functions are passed from one component to another Shared memory interface: ...
2
votes
3answers
194 views

Preemptive interfaces in Java - good, bad or “a matter of taste”

I frequently come across projects that strictly define an interface for each and every class. 90% of those interfaces feature only a single implementation. Proponents of these "preemptive interfacs" ...
1
vote
1answer
55 views

Recursive interface implementation causes empty method

TLDR: I have a situation where interface implementations accept other implementations of that very interface. Only a subselection of these interface implementations should carry a certain method - but ...
4
votes
1answer
125 views

Should an interface covariant on T ever implement an interface invariant on it?

I was reading through the Hacklang docs on Collections, and came across this curious definition [paraphrased slightly]: interface KeyedIterable<Tk, Tv> ... interface ConstVector<+Tv> ...
1
vote
1answer
135 views

Inheritance is better or composition design pattern in this scenario?

Design and implement Cash Register: Given a number of items you will be required to calculate the total bill. Items are charged for in a couple of different ways: A given price for each item, e.g. ...
0
votes
0answers
55 views

Using java interfaces to narrow the classes public interface

There is a lot of content on the web discussing if it is worth defining an interface if only one class implements it. The answers are mostly either "Yes, because you probably need to mock it anyways" ...
0
votes
2answers
137 views

Is interface containing every method of given class a good thing?

I'm trying to write a simple game and I really want to finally create something that would be "programmatically correct". I stuck with a problem like this: I have class public abstract class ...
1
vote
1answer
156 views

Should we “prefer composition over multiple interface”?

Should we avoid multiple interface if possible? Because I think at most cases a class with multiple interfaces can be replaced with another version with composition and single interface only e.g.: ...
127
votes
15answers
42k 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?
2
votes
2answers
127 views

Java: Composition of classes implementing same interface

Let's consider an example wherein I have to model the following: Class to schedule exams for a Student, lets call it StudentExamScheduler Class to schedule exam for a Class. Let's call it ...
0
votes
0answers
45 views

Code Duplication After Dependency Injection Instead Of Inheritance

I'm applying Dependency Injection instead of Inheritance. But now, I've the problem of code duplication. Main Controller final class PreferenceController implements PreferenceInterface { ...
9
votes
6answers
5k 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 it'...
0
votes
0answers
59 views

Heuristics/rules for programming to an interface [duplicate]

I am struggling with applying the "programming to an interface" guideline because I can't seem to decide in which situations it is necessary and in which ones it's overkill (or even counter productive)...
5
votes
1answer
3k views

Implicit vs explicit interfaces

I think I understand the actual limitations of compile-time polymorphism and run-time polymorphism. But what are the conceptual differences between explicit interfaces (run-time polymorphism. ie ...
0
votes
1answer
167 views

Should I force “composition over inheritance” rule to class members?

As I know, according to "composition over inheritance" rule, we should avoid reuse a method by inheritance, but how about class members? Suppose I have parent and child classes: public class Animal{ ...
2
votes
2answers
80 views

Revisiting Fowler's “Public versus Published Interfaces” article with regard to versioning and microservices

In this short article Public versus Published Interfaces from 2002, Martin Fowler distinguishes between easily changeable "public interfaces" and harder to change "published interfaces": The key ...
0
votes
0answers
78 views

Can I keep my code loosely coupled with public-facing enums?

I have some enums in a concrete API/library that will be publicly used by application projects. My problem here, is that I cannot write an interface to these enums (that I know of). I should have ...
0
votes
1answer
140 views

Isn't instantiating an object of type Interface illegal?

This answer describing how Spring for Java works instantiates an object of type Interface which is illegal yet it received 21 upvotes. Why is this answer upvoted for illegal behavior? Spring contains ...
4
votes
1answer
119 views

Why generic interface cannot implement dynamic type?

If it possible: IList <dynamic> = new List <dynamic>; or: class A <T> { A(T){} } class B: A <dynamic> {} . Why it is not possible to do this: class U: IEnumerable <...
1
vote
3answers
116 views

Same class and namespace name

I have a problem how to go about naming my namespaces and classes. I already figured they shouldn't both have the same name, as it causes all kinds of problems. Most notable problem for me is that I ...
1
vote
2answers
120 views

Will it be okay for an interface to take a dependency on an interface in this situation?

Background I have an interface defined for a circular-buffer called ICircularBuffer in a separate project. This ICircularBuffer is something that we use all over the place, so it resides in the ...
5
votes
1answer
122 views

Inheritance from children to parents?

Seeing this UML class diagram : FileHandler, Uploader and Deleter are abstract classes. The four bottom classes are implementations. They extend on FileHandlerInterface which requires a handle ...
1
vote
2answers
76 views

Passing and returning domain object in create method

We have this bean with two properties: ContainerImage + name (final, not null) + id (null) Then there is this method: ContainerImage create(ContainerImage containerImage); It receives ...
5
votes
1answer
69 views

Discoverable default implementation of an interface

I have a couple of simple classes that implement the Null Object pattern. To illustrate the hierarchy, let's define a Config interface with two classes implementing it ConfigItem and MissingConfig, ...
5
votes
4answers
798 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] ...
5
votes
2answers
80 views

Unused function parameters and polymorphism

I had a discussion with a co-worker about interface members having parameters that some implementations don't use. Say I have an interface interface IDoctor { string GetMedicalOpinion(Age age, ...
0
votes
1answer
68 views

Separate interfaces for dependency data providers?

I am attempting to refactor a component of a large project, which currently has a lot of dependencies to global state of the project environment. The goal (for my taste) is a "SOLID" architecture, ...
4
votes
2answers
283 views

Why is an abstract class forced to define all functions of an inherited interface?

Why does c# compiler force an abstract class to define (as opposed to implement) all the methods of the inherited interface ? why does it not mark unimplemented methods of an inherited interface as ...
0
votes
0answers
23 views

Making my dependencies available in my public interfaces

I've made a bute Visual Studio extension. It works, and now I want to make it extensible and add unit tests. I notice straight off that I'm passing around within my methods, and making available in my ...
7
votes
8answers
454 views

Does it make sense to declare private fields using an interface as their type?

For the fields that you have as encapsulated members of a class, does it make sense to declare their type to be of the interface that you are using? For example: public class PayrollInfo { private ...
7
votes
3answers
268 views

Using Interfaces for Loosely Coupled Code

Background I have a project that depends on the usage of a certain type of hardware device, while it doesn't really matter who makes that hardware device as long as it does what I need it to do. With ...
6
votes
4answers
290 views

Should every class I write adhere to an interface?

I'm writing a game in Typescript, and decided going in that I was going to try to adhere to the idea of "interface based programming", where you write code based on an interface, instead of the ...
1
vote
2answers
142 views

Should I be using IDisposable here, to properly manage memory?

Background I have an object that represents a test procedure that I need to run on a product. This object may be used multiple times during run-time, depending on how many times the user elects to ...
2
votes
0answers
104 views

What are the benefits of an input/output component design?

For the company I work at, all of our projects, including a new one started last year, are written in C89. We write for vxWorks (a real time embedded operation system). Our software runs multi-...
7
votes
3answers
5k views

What can I use instead of Interfaces in Ruby (or any other dynamic language)?

My goal is to define contracts between classes. I like duck typing and all but I'd like also to define an interface between different layers of my application to clearly define which are the method ...
27
votes
3answers
5k views

If I implement an Interface, is it called an Inheritance?

If my class implements an interface then can I say that I'm following inheritance? I know that when a class extends another class then it's inheritance.
1
vote
2answers
134 views

Expressing interface inheritance in natural language [duplicate]

In object-oriented programming, when you extend a class you establish an is-a relationship between a new subtype and its parent(s), i.e. B is an A (aka code inheritance). When you compose a class with ...
1
vote
2answers
178 views

Should i implement same interface in derived class?

Is there a difference between public class B implements C public class A extends B implements C and public class B implements C public class A extends B Is it just redundant implementation? ...
0
votes
1answer
104 views

How to make interfaces usable for special classes only?

Is there a way to make Java interfaces only implementable by classes of a special type? So for instance, I have a class Foo and an interface Bar. Only subclasses of Foo should be able to implement ...
2
votes
2answers
278 views

Interfaces and abstraction: takes more time?

At the company I work for I want to improve the way we write software: designing our applications more SOLID. We've been in a new project for a few weeks and I've tried to apply some good practices in ...
1
vote
1answer
144 views

What's the benefit of generics in an in interface e.g. IEnumerable<HttpPostedFileBase>

I've come across a method that requires a parameter that implements IEnumerable and is of a certain type like this: public myMethod (IEnumerable<HttpPostedFileBase> myParameter) { ...
16
votes
2answers
2k views

Principle of least astonishment (POLA) and interfaces

A good quarter of a century ago when I was learning C++, I was taught that interfaces should be forgiving and as far as possible not care about the order that methods were called since the consumer ...
0
votes
1answer
117 views

Passing a Serial Port Instance

Background I am thinking about designing a (GoF/behavioral) command-pattern interface. I may decide to call this thing ICommand. I am thinking that I would have some sort of a queue containing a ...
1
vote
0answers
40 views

Should I use RFC 2119 in interface documentation?

RFC 2119 defines several terms, including MUST, SHOULD, and MAY, for use in standards documents, particularly those relating to networking protocols such as IP and HTTP. These terms are widely used ...
2
votes
2answers
130 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 ...
4
votes
2answers
140 views

Understanding polymorphism and interface in Java

I'm reading though some notes. And I'm not understanding the following two statements. Polymorphism means that it is always the class of the actual object at run time that determines which method ...
14
votes
5answers
3k views

When to use interfaces (unit testing, IoC?)

I suspect I've made a schoolboy error here, and am looking for clarification. A lot of the classes in my solution (C#) - dare I say the majority - I've ended up writing a corresponding interface for. ...
2
votes
2answers
136 views

Why would an interface override methods of the interface(s) it extends in Java 7?

I was looking at Map and SortedMap documentation from Java 7 and I have realized that SortedMap, which extends Map overrides entrySet(), keySet() and values(). AFAIK, interfaces cannot implement a ...
4
votes
3answers
132 views

How should I write an interface that takes a list of items?

I'm writing a library function that takes a list (or "bunch") of items (let's say Student) and does something with them. What's the best way to write the function signature in the interface? std::...