Questions tagged [interfaces]
Questions about `interface` related design considerations, and also "programming to the interface instead of the implementation"
725
questions
6
votes
2
answers
1k
views
Naming an interface that does something and its opposite
Maybe I'm overthinking about naming, but it's a problem I've encountered several times and it was really annoying every time.
I have three interfaces. The first is IAssembler, which has assemble(...) ...
6
votes
4
answers
10k
views
Are empty interfaces (but not marker interfaces) a bad programming practice?
I'm designing an architecture in which I have:
public interface IObjectReader{
public Object read();
}
public class ConcreteObjectReader implements IObjectReader{
@Override
public ...
6
votes
3
answers
18k
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 ...
6
votes
2
answers
5k
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, ...
6
votes
9
answers
3k
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 ...
6
votes
4
answers
16k
views
Abstract class + Inheritance vs Interface
Hello fellow programmers,
I am reading a book on C# and the author is comparing Abstract classes and Interfaces. He claims that if you have the following "abstract class:"
abstract class ...
6
votes
4
answers
1k
views
Should custom exceptions live with the interface or the implementation?
I have an interface IMyService in a class library.
I have an implementation of this interface MyService in a separate class library.
MyService may raise a custom exception CustomException.
Should ...
6
votes
1
answer
2k
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 when ...
6
votes
2
answers
859
views
Is excessive indirection and/or redundant encapsulation a recognized concept? [closed]
I'm curious if there's a series of tendencies or anti-patterns when programming whereby a developer will always locally re-wrap external dependencies when consuming them.
A slightly less vague ...
6
votes
1
answer
2k
views
How should equality be defined for classes that implement same interface?
Suppose I have two classes that implement the same interface, as in the example in C# below:
public interface ICommonInterface
{
string Text { get; }
int Count { get; }
}
public class ...
6
votes
5
answers
1k
views
Is there something wrong with having one interface to be implemented multiple times in inheritance chain?
interface IUser {}
interface IConcreteUser : IUser {}
abstract class UserBase : IUser {}
class ConcreteUser : UserBase, IConcreteUser {}
As you can see, ConcreteUser inherits IUser two times - one ...
6
votes
5
answers
2k
views
Should all class public methods come from an interface?
I'm currently learning about TDD techniques, one of the suggestion is to test only public methods and skip the private ones. I have also been reading about Mocking. If I want to mock a certain method, ...
6
votes
1
answer
1k
views
How does dependency inversion principle work in languages without interfaces?
In C#/Java, the dependency inversion principle is often demonstrated by high-level classes that depends on an interface/abstraction (that it owns). Low-level classes will implement the interface, thus ...
6
votes
4
answers
783
views
Evolving an interface that is not supposed to be implemented by the client
I'm about to write a Java library. Basically, this library provides something like this to its user:
interface Foo {
void doA();
boolean aWorked();
void doB(int value);
}
The user is not ...
6
votes
2
answers
590
views
Is it good design to have one constructor that supplies a "default" concrete class to another that takes an abstraction?
I like to invert dependencies whenever possible by depending mostly on abstraction and allowing the concrete implementations to be passed into the object by clients, or a factory. I've found this to ...
6
votes
1
answer
960
views
What is the origin of "Program to an interface, not an implementation"? [closed]
What is the origin of "Program to an interface, not an implementation"?
Does it originate from Design Patterns, 1994, by GoF, or from a computer scientist or from some concepts in computer ...
6
votes
1
answer
449
views
Properly integrate an IDL into multiple git repositories
IDLs like Protobuf, flatbuffers, Cap'n Proto or Thrift allow communication over standardised interfaces between otherwise independent projects.
Most often, these projects will be developed in ...
6
votes
5
answers
20k
views
How to Model a simple file-system by UML class diagram
I want to model a file system which contains both files and directories, and directories can contain either files or other directories.
This is what I have reached so far:
In OOSE book, however, a ...
6
votes
1
answer
3k
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 ...
6
votes
1
answer
499
views
Designing module interfaces
I'm studying software engineering and one thing I'm really trying to improve is my skill in software architecture. My question is quite broad, so I'll try to explain it with an example.
Suppose you ...
5
votes
5
answers
2k
views
How to think when grouping functionality into modules
What are some commonly used strategies when it comes to divide software into modules, other than there should not be any cyclic dependency between any modules? Some ways I think of
Group everything ...
5
votes
6
answers
25k
views
Design Patterns - Why the need for interfaces?
OK. I am learning design patterns. Every time I see someone code an example of a design pattern they use interfaces. Here is an example:
http://visualstudiomagazine.com/Articles/2013/06/18/the-facade-...
5
votes
2
answers
6k
views
C++ class with only pure virtual functions: what's that called?
So i'm looking for some input/consensus on what terminology we should be using to describe something that looks like this:
class Printable
{
public:
virtual void printTo(Printer *) = 0;
...
5
votes
3
answers
1k
views
Switching from abstract class to interface
I have an abstract class which has all abstract methods except one which constructs objects of the subclasses. Now my mentor asked me to move this abstract class to an interface.
Having an interface ...
5
votes
3
answers
447
views
Where should I place my interface?
I have an interface to communicate with a DB (actually it is not a database, but this is to give a concrete example):
interface DbInterface{
Result sendQuery(Query q);
}
And I am trying to ...
5
votes
2
answers
636
views
Function that requires many parameters
I have a problem related to this:
Are there guidelines on how many parameters a function should accept?
In my case, I have a function that describes a rounded rectangle. The caller specifies
An ...
5
votes
2
answers
3k
views
Interface extension method returning the interface type in C#
Programming against interfaces is an often-heard good practice in software development. Together with extension methods, this provides a great functionality. However, in C#, there are limitations to ...
5
votes
2
answers
4k
views
when using dependency injection, should I always pass an interface
When using depending injection, you generally pass everything around as an interface (perhaps with the exception of primitives and strings). That allows you to easily chance the behavior, without ...
5
votes
2
answers
3k
views
How to create contracts in python
I am currently learning Python (from Java) and have a question on contracts.
Example: an application defines an interface that all plugins must implement and then the main application can call it.
...
5
votes
1
answer
1k
views
Why were default methods introduced to Java?
Was introducing default methods to java inevitable? As far as I know multiple class inheritance was not introduced to avoid difficulties with the method signature clash in base classes.
So we avoided ...
5
votes
1
answer
1k
views
How to go ahead with methods that only one derived class implements from a common interface?
I have one interface (let's say in C++) that has been implemented by some derived classes. Let's suppose that the interface is like this:
class IBase
{
virtual bool method_1() = 0;
virtual long ...
5
votes
3
answers
2k
views
Java - Does an Interface really have no state or behavior?
going through the web I always read something like
Java Interfaces have no state and no behavior
If you look what the common definition of state is then you likely end with
what the objects ...
5
votes
4
answers
2k
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....
5
votes
3
answers
988
views
Naming conventions for the only envisioned implementation of an interface [closed]
If you decide "Program to An Interface" trumps YAGNI and decide to create a supertype where you don't envision anything other than one obvious implementation - is there a convention for naming the ...
5
votes
4
answers
3k
views
Which methods should be put in an interface and which in abstract classes?
I have seen many frameworks and modules and their standard they follow is like this
UserInterface which have some predefined methods
AbstractUserClass which implements userInterface
Then ...
5
votes
1
answer
551
views
Why aren't there Dimension and Point interfaces?
I mean something along the lines of:
public interface Dimensioned {
int getWidth();
int getHeight();
}
and
public interface Positioned {
int getX();
int getY();
}
There are a lot ...
5
votes
3
answers
1k
views
Is it true that "A Java Iterator is an Abstract Data Type"?
I'm trying to deepen my understanding on this, the only thing I know for sure is that Iterator is an interface in Java.
I've been reading CS literature, for example here and here and looking for ...
5
votes
1
answer
257
views
Sometimes, "programming to interfaces" introduces possible (and avoidable) runtime exceptions?
Please consider the com.google.common.collect.ImmutableMap
Programming to its interface, Map , creates a bug that could blow-up in the runtime as such:
Map<String, Integer> myMap = ...
5
votes
4
answers
815
views
Passing compound object for parameters
I have different data modules, which take a couple of parameters from a configuration list. Do you think it's ok to pass a configuration object as a whole module1(config) and let the module pick what ...
5
votes
2
answers
212
views
How to bring others to understand your interface
I'm working in a corporation that has two products. One is a desktop application the other is a web-application. I'm in on the part as backend-engineer on the web-application. I design the web-...
5
votes
1
answer
6k
views
Interface with multiple default methods OR Interface + Class
In a code base I am "starting from" there are a handful of interfaces with many default methods. They look something like this:
public interface HasXY {
double getX();
double getY();
...
5
votes
3
answers
529
views
Does it make sense to split up an existing multi-method interface into several single method interfaces just to take advantage of lambdas?
Say I have an existing callback interface that has multiple methods. To illustrate my point I use a callback the likes that you would see in code that performs some HTTP client operations:
public ...
5
votes
1
answer
198
views
Selectively exposing interface of inner members
I have a class called D2Array which represents a fixed-size 2D array. It's meant to be generic and it comes with quite its lot of methods: getting an element, setting an element, extract a whole row, ...
5
votes
2
answers
839
views
Is it acceptable to make changes to an interface during implementation?
When writing a library/API for the first time I'll usually start by sketching some ideas on a white-board or loose-leaf while thinking about how different parts of the system interact. This usually ...
5
votes
2
answers
4k
views
Library IO: Use Interface classes or Callbacks?
I'm building a smallish library (few kLOC) which processes stream data in C++. From the streamed data (comes in packets) the library compiles a database piece by piece and naturally has to convey that ...
5
votes
1
answer
7k
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 and ...
5
votes
2
answers
325
views
C programming multiple storage backends
I am starting a side project in C which requires multiple storage backends to be driven by a particular piece of logic. These storage backends would each be linked with the decision of which one to ...
5
votes
2
answers
182
views
Using a openid in a "closed system"
I would like to publish a website for certain family members only. Simply put, like a mishmash of family photos and videos. I want it to remain private, however.
I was considering using openid for ...
5
votes
3
answers
343
views
Should you use popular(e.g. OpenCV,boost, Eigen, Tensorflow) types on your interfaces?
Suppose you are writing a software where there is a popular existing library that does not have all the algorithms/features you want but provides some "vocabulary" (equivalents of std::vector/std::...
5
votes
2
answers
3k
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 ...