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

learn more… | top users | synonyms (1)

9
votes
2answers
480 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
202 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; } List&...
3
votes
6answers
177 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
350 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
2k 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
167 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
198 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
231 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 don'...
0
votes
4answers
386 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 ...
4
votes
3answers
729 views

Generics vs common interface?

I don't remember when I wrote generic class last time. Every time I think I need it after some thinking I make a conclusion I don't. The second answer to this question made me to ask for ...
3
votes
3answers
149 views

Communicating to an Object from another without coupling in java?

So I have a Person object, and a GumballMachine object. The behavior I'm searching for is, in the intent to avoid unnecessary coupling, have the method insertCoin() called from within the Person ...
5
votes
3answers
420 views

Composition over inheritance but

I'm trying to teach myself software engineering and coming up against some conflicting information which is confusing me. I've been learning OOP and what abstract classes / Interfaces are and how to ...
3
votes
2answers
563 views

Should the main method be separate in a separate class? [closed]

In Java main methods often do little more than parsing the command line arguments and initializing an object that then takes over, for example: public class FooServer { // ... public static ...
4
votes
1answer
224 views

UML: Should an asynchronous request-response message exchange be modelled as two ports/interfaces or one

I want to model an asynchronous request-response message exchange in UML. The request is sent from a client to a server. The server responses asynchronously. This can be modelled in a component ...
0
votes
0answers
26 views

Text based command/interface design

When using inter-process communication (pipes, memory streams, ...), I typically have a byte stream to communicate, also with http (unless using some heavy-weight web framework), the body comes as a ...
1
vote
2answers
210 views

To god (class) or not to god? [duplicate]

I'm working on a project that requires several different users in the system, all of which have overlapping responsibilities; we've isolated two possible ways of tackling this problem, but we're ...
0
votes
1answer
98 views

When designing input interfaces for a library, when to use data class rather than data interface?

Let's say library A, B and C are all custom math libraries. They may or may not use the same data types. The libraries have methods that accept data type inputs like ProcessAsync(DataTypeA) or ...
1
vote
1answer
142 views

Interface Design: Specific vs General parameter (A Minimal design vs anticipated use variation)

Code public interface IVehicle { string VehicleMake { get; } int MonthsSincePurchase { get; } bool IsApprovedUsed { get; } ... } public class WarrantyPopUpHandler { virtual bool ...
-3
votes
1answer
145 views

Why can't I return an implementation of an interface for a method that requests the interface? [closed]

I am implementing an interface I on a class A. Class A implements I. I have an Iterator T that is supposed to return an object which implements I everytime I call next. My iterator goes as follows (...
1
vote
2answers
294 views

What are the justifications for annotations in a programming language? [closed]

After spending a great deal of time writing C# and looking at Java, it seems to me that annotations are just an ugly code smell that introduce another conceptual layer that could easily be replaced by ...
0
votes
1answer
165 views

Coding to an interface vs more generic interfaces

I have a number of classes (and interfaces) which 'code to an interface' interface File { ... } interface FileConverter { public function convert(File $file); //coding to an interface ...
2
votes
1answer
81 views

Reusing an interface or method chaining

I am learning about coding to an interface in OOP programming. I understand you should code to an interface so you can 'swap out' functionality. However, I have a situation where I feel I can reuse ...
0
votes
4answers
634 views

How is an interface used in Dependency Injection?

I'm working on a simple DI library, and on the subject of using services through interfaces, I can't find the usefulness. Perhaps it's because I dont fully or properly understand how an interface ...
2
votes
1answer
157 views

Using own ArrayList in general purpose C libraries, but allowing a different implementation

I've written a couple of libraries since beginning to use C again last year. One thing that still needs addressing in both of these is the correct use of array-based lists - hereafter, ArrayLists. At ...
1
vote
1answer
61 views

MVC .NET APP Program Structure [closed]

I am just building a MVC .NET application, eventually this will use entity framework and the repository pattern to structure the program. The first release however will only be calling other jobs that ...
1
vote
2answers
187 views

Better application design - where to place interfaces

Where to place interfaces in a typical multi-layered app with DataAccess, BusinessLogic and an Endpoint modules? I propose 2 options In both cases there's only dependency from abstractions, but in ...
2
votes
3answers
403 views

Manual Dependency Injection Examples Still Tightly Coupled

I've been using AutoFac for some time now to take care of the dependency injection we're using in a web project. All is well, but I now want to demonstrate DI outside of an AutoFac context for reasons ...
0
votes
1answer
43 views

How do I use type assertions in Go when returning an interface type?

A struct I'm working on called fieldDefinition holds metadata about a field used by an object in my web app. One of the fields on fieldDefinition (it does get a bit confusing) looks something like ...
4
votes
4answers
372 views

Should an application configuration interface be broken into multiple interfaces to reduce feature creep?

My windows service is neatly separated into 5 components - each with their own interface and pulled together by a bootstrapper. One of my requirements is to provide configuration options in my app....
0
votes
1answer
81 views

Should I separate the interface or use single one [closed]

I'm developing a game, I will generate objects. I have create an interface called IObject which has the following properties: String tag // Tag for the object Vector3 position // Where the element is ...
3
votes
4answers
341 views

Design: Lisp (or other scripting language) as an interactive interface for C++?

I'm working on a medium size C++ project (will probably end up around 50k lines) and I have to provide an interactive terminal interface. The program produces scientific data as an output and the ...
1
vote
2answers
178 views

Could changing the return type from void to string introduce breaking changes?

This SDK have an interface like this: public interface Contract { void update(..); void action(..); void delete(..); } Now, we need to change it to something like this: public ...
3
votes
4answers
216 views

Design strategy for wrapping exceptions

I'm implementing a type of Repository for a framework/library that has (roughly) the following: public interface FooRepository { boolean contains(String id); Foo fetch(String id); void ...
1
vote
1answer
169 views

Inefficient use of interfaces in OOP (C#)

In my code, I've got two interfaces, let's say IOpenable and IExaminable. IOpenable allows the user to Open or Close the object, and IExaminable allows the user to Examine the object. Now, we have ...
2
votes
1answer
142 views

Define an object with the interface as a type instead of class name [duplicate]

I try to practice with the design patterns and explore one of the possible implementations of the Observer Design Pattern in Java. I paid attention, that in this example the object is defined with the ...
7
votes
2answers
206 views

Optional features: default method or separated interface

Dedicated interfaces seems to be a good way to expose the optional features in a domain-specific type hierarchy. However, they impede the use of decorator and composite patterns, which is also common ...
11
votes
3answers
1k views

Is an interface considered 'empty' if it inherits from other interfaces?

Empty interfaces are generally consider bad practice, as far as I can tell - especially where things like attributes are supported by the language. However, is an interface considered 'empty' if it ...
1
vote
2answers
45 views

Declaring 'chained' interface inheritance

I assume this is largely language-agnostic, but I'm working in C# if it's not Let's say interface I3 inherits from I2, which in turn inherits from I1. I could write this: interface I1 { ... } ...
3
votes
1answer
139 views

Interfaces, abstraction, coding to an interface

Original question here I am learning OOP and SOLID. I have a 'main' class that performs some actions after reading variables from a config file. This 'main' class is not the focus of this question ...
1
vote
2answers
242 views

Convert this abstract class to an interface

I have a security method I would like to be able to sprinkle into other classes throughout my program. It is currently an abstract class but I feel it would be more appropriate as an interface. Can ...
12
votes
2answers
552 views

UnsupportedOperationException in java collections framework interfaces

Looking through the Java Collections Framework, I've noticed quite a few of the interfaces have the comment (optional operation). These methods allow implementing classes to through an ...
-3
votes
2answers
162 views

Advantages of these recommendations in ooprogramming using Java

Below are the recommendation from section 5.1 of this essay. While Java is not a pure object-oriented language, it is possible to program in a pure object-oriented style by obeying the following ...
0
votes
3answers
451 views

Why List<E> interface is additionally introduced in collection hierarchy? [duplicate]

Below is the diagram, where, if we just consider the implementations of List, AbstractList maintains the core behavior of list. To introduce the new implementation class MyList(say) one can ...
3
votes
1answer
349 views

Creating an interface just to decouple from third party libraries

I'm currently developing the Authorization module on a framework of mine. I have the following class so far: public interface IAuthorizationManager<C> where C : ...
0
votes
1answer
80 views

What would this interface be called? [closed]

At work we have a java backend that talks to python on some mobile devices. The mobile devices have no GUI, it's just pure string manipulation. All contact is initiated by the python; the java is just ...
2
votes
1answer
91 views

How valuable is decoupling in proprietary software?

When developing with Symfony2 PHP framework I often see reccomendations to decouple code but most of the time that is accompanied by a 'if you want to release as a third party bundle'. Which begs the ...
0
votes
1answer
72 views

What should this interface contain?

I am creating a schema for Doctrine but first I'm creating interfaces, abstract classes (models) which will be extended by the entities. I have a PresentationInterface which contain getter and ...
-2
votes
1answer
74 views

Programming to an Interface and Keep Testability in Unique Classes [duplicate]

I try to program to an interface whenever possible, but when I have a class that fulfills a very specific and unique purpose, one that can't be abstracted. Is it correct for me to say that I've ...
1
vote
3answers
100 views

Programming to an Interface and Interface Segregation in the Context of a User Class [duplicate]

I try to program to an interface whenever possible, but its not clear to me how I could apply it to a model as broad as a user. Which can hold many disparate fields (name, age, phone number, ssn, etc.)...