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

learn more… | top users | synonyms (1)

1
vote
0answers
8 views

Heuristics/rules for programming to an interface

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
156 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{ ...
1
vote
1answer
381 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 ...
4
votes
1answer
109 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> ...
2
votes
2answers
69 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
71 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
138 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
102 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
104 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
115 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
113 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
75 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
64 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
784 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] ...
4
votes
2answers
62 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
66 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
259 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
453 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
243 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
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'...
5
votes
4answers
280 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
134 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
103 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
4k 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
133 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
165 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
100 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
277 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
136 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
94 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
137 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
127 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
129 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::...
0
votes
0answers
35 views

Usage of “Passive View” for winforms application

I'm currently working on a winforms project which will have a rather complex structure with about 300/400 controls which I will have to access during the program is running. I am contemplating the ...
3
votes
1answer
68 views

Within an interface specified by a core component, should it request IReadOnlyCollection or IEnumerable?

In thinking about the principle of "be conservative in what you send and liberal in what you accept", I generally try to make my methods receive IEnumerable parameters, but emit a IReadOnlyCollection (...
0
votes
2answers
174 views

How to organize and label methods intended for debug?

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

What to do if I need more than one base class in C#? [closed]

Let's say I have a grid with square fields. For the fields I have an abstract Field class. This class has several subclasses, for example EmptyField or RoadField. Some of these fields can be connected ...
2
votes
1answer
125 views

Lower class count vs explicitness

To help with an application that manipulates and works from an XML structure to produce other information, I've created a class structure that closely follows the XML structure. So, the XML is: <...
44
votes
7answers
12k views

Should interface names begin with an “I” prefix?

I have been reading "Clean Code" by Robert Martin to hopefully, become a better programmer. While none of it so far has been really ground breaking it has made me think differently about the way I ...
1
vote
1answer
53 views

Package Interfaces - Coupling & Re-Usability

Intent Packages should be designed to perform a single function well. Ideally this means that they should be highly modular and different packages should be able to be 'plugged-in' simply by ...
2
votes
1answer
250 views

Structuring projects in a solution for interfaces

I had this idea that I would achieve some good automation and separation of concerns as follows: Define an interface, IDataProvider, in a class in a DataMuncher project that needs to both consume ...
3
votes
1answer
238 views

Why covariance is forbidden for abstract class in C#

I've been digging in covariance and contravariance in C# and there is one thing I could not manage to understand. C# (AFAIK, as of 4 version) allows one to declare the covariant or contravariant ...
2
votes
3answers
175 views

When and why would you extract an abstract method from an abstract class to an interface?

I have been asked the following question in an interview: "What is the need of an interface when you can have an abstract method within an abstract class?" Which I did not know the answer to. Could ...