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

learn more… | top users | synonyms (1)

1
vote
2answers
74 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 ...
1
vote
1answer
361 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 ...
3
votes
1answer
99 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> ...
5
votes
1answer
61 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
779 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
59 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
64 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
236 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
440 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
216 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
4k 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 ...
5
votes
4answers
266 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
126 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
83 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 ...
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
132 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
162 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
96 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
133 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
81 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
38 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
136 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 ...
13
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
124 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
127 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? ...
0
votes
0answers
29 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
67 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
195 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
123 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: ...
42
votes
7answers
11k 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
199 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
225 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
172 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 ...
1
vote
1answer
82 views

Use the chance to return booleans after method calls for an optional layer of exception handling? [duplicate]

I would like to ask a follow-up to a question I just asked: Better to have 2 methods with clear meaning, or just 1 dual use method? I now understand why it is best to separate charge(float c); and ...
27
votes
6answers
3k views

Better to have 2 methods with clear meaning, or just 1 dual use method?

To simplify the interface, is it better to just not have the getBalance() method? Passing 0 to the charge(float c); will give the same result: public class Client { private float bal; float ...
2
votes
1answer
246 views

Open / Closed Principle

I found this code example explaining Open / Closed principle. Code before application of principle: public class Logger { public void Log(string message, LogType logType) { switch ...
0
votes
0answers
56 views

Software Architecture: CQRS and port modeling

I have a PersonComponent, which an internal implementation is based on CQRS pattern. So which one is better way to model ports (and their interfaces): I'm not totally sure that how high or low ...
14
votes
3answers
19k 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 ...
8
votes
3answers
1k 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 ...
0
votes
1answer
153 views

Neat way on passing interface parameter to a constructor

Having lots of Interface that needs to pass in a constructor looks messy, is there any neat way of doing it? Code snippet: public class Foo { private readonly IRepository1 _repository1; ...
1
vote
2answers
113 views

Does an interface including several methods that return instances of Object make sense?

I am in the process of writing my first true API. In the process, I am defining an interface for mapping complex data structures onto other complex data structures. At the moment, the interface ...
-2
votes
1answer
179 views

Why are interfaces necessary in MVP design pattern?

I am trying to understands MVP using Winforms. I found this example. Why do UserModel and UserView need to implement the IUserModel and IUserView interfaces ?
1
vote
2answers
90 views

Where to inject dependency required by all implementors of an interface?

I have an interface whose job is to communicate with repository (that implements some interface). It doesn't seem to make sense to implement this interface without receiving a repository,so I'd like ...