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

learn more… | top users | synonyms (1)

5
votes
1answer
60 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, ...
3
votes
2answers
53 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
0answers
22 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 ...
0
votes
1answer
63 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, ...
7
votes
3answers
213 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 ...
4
votes
2answers
235 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 ...
6
votes
8answers
435 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 ...
4
votes
4answers
259 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
82 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 ...
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
161 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
95 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 ...
1
vote
1answer
132 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) { ...
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 ...
0
votes
1answer
78 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 ...
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 ...
4
votes
2answers
134 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 ...
2
votes
2answers
123 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? ...
3
votes
1answer
98 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> ...
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
3answers
193 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: ...
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 ...
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 ...
26
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 ...
0
votes
1answer
149 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; ...
-2
votes
1answer
173 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
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 ...
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 ...
0
votes
1answer
114 views

Can I enforce the overriding of GetHashCode() and Equals() methods for users of a generic container class?

I have a container class similar to the one below (with much of the logic omitted): class Container<T> { Dictionary<T, TWrapped> contains = new Dictionary<T, TWrapper>(); ...
1
vote
3answers
302 views

How can I sell DRY? [closed]

Where I work we have around 10 VS projects in a solution which are identical in functionality (with some different different rules in a few methods) and share many exact methods. They share the same ...
2
votes
1answer
186 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 ...
2
votes
2answers
74 views

Where to put configuration constants?

Considering a small embedded C project, how to decide if certain constants belong to a global configuration file the header of the "module == compilation unit" on top of the the actual C file or ...
9
votes
2answers
474 views

Interface Segregation Principle: What to do if interfaces have significant overlap?

From Agile Software Development, Principles, Patterns, and Practices: Pearson New International Edition: Sometimes, the methods invoked by different groups of clients will overlap. If the overlap ...
9
votes
2answers
199 views

Programming to Data Oriented Interfaces

There is a portion of our codebase written in the following style: // IScheduledTask.cs public interface IScheduledTask { string TaskName { get; set; } int TaskPriority { get; set; } ...
3
votes
6answers
173 views

If Class is to define attributes and methods, and Interface is to define (a set of) methods, then how to think of interface needing new attributes?

I thought a class is supposed to define, or give a blueprint, of attributes and methods for an object. And then, an interface is to provide a set of methods, as a contract for its clients. (and so a ...
4
votes
2answers
349 views

How and when did it happen that, a type is an interface?

I came from a highly functional and procedural background in programming, and never knew that a type is the same as an interface. As in the Design Patterns book by GoF, it says: A type is a name ...
21
votes
5answers
1k views

Implementing an interface when you don't need one of the properties

Pretty straight-forward. I'm implementing an interface, but there's one property that is unnecessary for this class and, in fact, shouldn't be used. My initial idea was to just do something like: int ...
1
vote
1answer
154 views

When should interface be owned by client?

In Agile Software Development: Principles, Patterns, and Practices, Uncle Bob talks about client owning the service interface. My questions are : Should client always own the interface or only ...
2
votes
3answers
183 views

What is the purpose of a wrapper class that does nothing but delegate to the object it wraps?

The specific example I have in mind is javax.servlet.ServletResponseWrapper: public class ServletResponseWrapper implements ServletResponse { private ServletResponse response; /** * The ...
3
votes
3answers
228 views

How to “program to an interface”

I've read these questions: Understanding "programming to an interface" What is the point of an interface? Does it always make sense to "program to an interface" in Java? I ...
0
votes
4answers
382 views

In C#, what is the benefit of assigning a class variable to an interface variable before calling any methods?

Where I work we develop in C# .NET and I was looking a code that they have made (my job is to optimize it) but I saw something in particular: Assuming that InterfaceDHO is an interface and ClassDHO ...
0
votes
2answers
118 views

Best practice for encapsulating a parameter that requires multiple interfaces to be implemented

I encounter this issue multiple times, but I'm never sure how best to deal with it. Basically, some methods I write require the implementing object to support multiple interfaces. The example I have ...