Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
62 views

Are complex return types the answer to being able to depend on objects that implement said interface?

Assume I have an Ingest object that will only work with objects that implemented the MyInterface interface. The ingester takes all the said objects but our language does not have complex return types, ...
2
votes
1answer
90 views

Heterogeneous interface hierarchy

I'm working on a program that tests a digital circuit. The digital circuit can process accesses from multiple different caches, CACHE0, CACHE1, etc. The digital circuit can handle accesses to ...
2
votes
1answer
139 views

C++ How to build a common interface with the possibility to call functions specific to only one class

I am building a common interface for several different backends that are shared libs loaded at runtime dependend on the used platform. It looks basically like the code below. My problem is, that while ...
9
votes
6answers
3k views

Split up large interfaces

I'm using a large interface with about 50 methods to access a database. The interface has been written by a colleague of mine. We discussed this: Me: 50 methods is too much. It's a code smell. ...
5
votes
1answer
725 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 ...
1
vote
1answer
110 views

Proper way of handling large Dependency Injected constructors [duplicate]

I have many dataservices/classes injected into a constructor. public MyClassConstructor (IAclass A, IBclass B, .... , IZclass Z){ ... } The number I have to pass down goes well beyond 100. To ...
0
votes
1answer
72 views

Avoiding downcasting in PHP

This is a theoretical problem that bothers me. Let's say we have following, simplified structure: interface ParagraphInterface {} interface ParagraphGroupInterface { public function ...
0
votes
3answers
89 views

DDD and Infrastructure micro-Services - how should the interface be designed?

We've extracted our email sending into an EmailService - this is a microservice that provides resiliency and abstracts the email logic into an Infrastructure service. The question is how the ...
0
votes
0answers
59 views

Using virtual inheritance for an interface system based on abstract classes

I want to use a physics engine (like bullet or PhysX) in my program, however I want to hide the actual physics engine from it, so I can easily swap it out with another during run-time (e.g. switch ...
0
votes
0answers
17 views

Feedback: data model and interface design for scraper

I'm writing a pet project to scrape some websites, and write out results to HTML. Currently my data model and interfaces are: class Post: def __init__(self, title, description, images) ...
-2
votes
1answer
134 views

UML class diagrams - how do I draw a class diagram that shows a self-reference? [closed]

So I have the following case. I have an interface A and an implementation AImpl. Now I have another implementation of A, called A2Impl, which references any instance of A besides implementing A ...
0
votes
2answers
134 views

What can I use as an alternative to protected interface methods in Java?

Occasionally, I want to write an interface that provides some complex method, and I want to make that a default method that uses some protected helper methods. The objective is such that I can later ...
2
votes
3answers
479 views

How to test required but accidental functionality?

For example, let's say I write a container class, which supports 2 kinds of operations: insert(x): inserts an element get_all(): retrieves all previously inserted elements Maybe it has some kind of ...
234
votes
15answers
100k views

Do I need to use an interface when only one class will ever implement it?

Isn't the whole point of an interface that multiple classes adhere to a set of rules and implementations?
1
vote
4answers
223 views

Interface with similar methods

I'm currently taking over a project that has a common pattern of interfaces like this: public interface EmailService { void sendInvitationEmail(Payload payload); void sendNotificationEmailToAdmin(...
5
votes
3answers
385 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 ...
15
votes
5answers
4k views

Pass object twice to same method or consolidate with combined interface?

I have a method that creates a data file after talking to a digital board: CreateDataFile(IFileAccess boardFileAccess, IMeasurer boardMeasurer) Here boardFileAccess and boardMeasurer are the same ...
1
vote
1answer
227 views

How to represent a specific type of interface dependency in component diagram?

I'm currently having a hard time with creating a component diagram that should represent a certain type of component/interface dependency and hope that you can give me some hints. As background, I ...
10
votes
8answers
909 views

Is an interface exposing async functions a leaky abstraction?

I'm reading the book Dependency Injection Principles, Practices, and Patterns and I read about the concept of leaky abstraction which is well described in the book. These days I'm refactoring a C# ...
1
vote
1answer
155 views

Should an abstract class implement an interface, as opposed to defining its own abstract methods?

I'm defining a class structure for persisting to our cassandra database, and I'm unsure about using a combination of an abstract class and an interface. I have two concrete classes, one for persisting ...
3
votes
3answers
517 views

Is it bad practice to create an interface only to combine two other interfaces?

I'm working on an infrastructure for inter process communication. I have created two interfaces, one to send data and another one to listen to data being sent: public interface ISender<T> : ...
2
votes
1answer
167 views

Would de-coupling using interfaces/templates make the system easier to maintain at the cost of over-engineering?

I have been practicing this hybrid approach for dependency injection in the last couple of days and I am wondering if it should also apply to components which are within the same package? For example:...
8
votes
7answers
6k views

How to enforce implementation of interface to behave a certain way

Suppose you had the following interface public interface IUserRepository { User GetByID(int userID); } How would you enforce implementers of this interface to throw an exception if a user is not ...
2
votes
1answer
85 views

Modeling “nested” interfaces in UML

I am modeling a system that exposes a number of "plugins" (not known at modeling time) through a web API. I have a number of "system" plugins that permit to interact with the system, something like "...
1
vote
1answer
188 views

How to manage context: set as property on class, or pass as parameter with each method?

I am writing a service, which is to be consumed by API and Web controllers. The result of each call depends on a UserContext state. Should I pass this UserContext with each method, which includes a ...
90
votes
12answers
18k views

What is meant by the phrase “Software can replace hardware”?

Studying beginners course on hardware/software interface and operating systems, often come up the topic of if it would be better to replace some hardware parts with software and vice-versa. I can't ...
3
votes
1answer
254 views

Understanding interface injection

Quoting the definition of interface injection from Wikipedia : The advantage of interface injection is that dependencies can be completely ignorant of their clients yet can still receive a ...
0
votes
3answers
90 views

How to “open interfaces to expansion” without breaking existing implementations?

For example, I have an interface Requests that basically lists all the requests a client can make to a server program. Now an obvious problem arises where I have to add a new request to the program i....
1
vote
0answers
248 views

Designing a multithreaded TCP/UDP server for audio sharing

As briefly introduced in the question title, I am trying to design and implement a server application able to let clients share audio contents between themselves. In order to achieve that, I decided ...
0
votes
1answer
98 views

One-field interfaces

I have an interface with only one title field: protocol Artist { var title: String { get } } (A) Should I pass the whole object as I did here: class Album { func setArtist(_ artist: Artist) ...
3
votes
3answers
457 views

How to decide, should I put methods to abstract class or to interface?

I'm writing an app it needs to have generic registration step item. It needs to be able to do some specific things (I use interface for that) and it needs to be a visual element (of Xamarin. It doesn'...
0
votes
1answer
591 views

Factory Design Pattern Implementation with multiple interfaces and base class

I know it is lot of code. But I am trying to understand the concept of Factory pattern with interfaces and base class. I have a base class of Car that implements an interface which will be implemented ...
1
vote
3answers
131 views

Should we inherit from base class and implement interface in this scenarios?

I am new to object oriented design and learning about interfaces and design patterns. In this example, I am trying to create class for cars. My question: Is it good practice to use base class and ...
91
votes
15answers
16k views

Should we design our code from the beginning to enable unit testing?

There's a debate going on in our team at the moment as to whether modifying code design to allow unit testing is a code smell, or to what extent it can be done without being a code smell. This has ...
0
votes
3answers
274 views

What would be the downsides of creating a derived interface of interface?

Would there be any downsides of creating sub-interfaces for virtual member functions that have different parameter types? A drawing of this is shown in the image attached. Apple and Orange do not ...
0
votes
0answers
29 views

Rely only on status or provide response explicitly? - SOA -

I am developing a set of SOA services where the backends (mainly stored procedures in the DB) sometimes return only status code as response (ex: an operation to cancel a ticket, the SP for this ...
0
votes
2answers
202 views

Which option is good in terms of software design?

I have one request interface IRequest and two classes ClientAddress and ClientOrder are implementing it. The same design is followed for Response with inteface IResponse and classes ...
3
votes
2answers
89 views

How are settings structured when they can be configured in diffferent ways?

Suppose of this question the following: I'm in full control of this project I'm writing a media player Obviously, a media player will allow a user to adjust the volume, so I might have a class that ...
-1
votes
1answer
88 views

add new class that implement base interface but need one more parameter

I have few strategy class that calculate ranking. Those class implements interface with method scoreUpdates. Method scoreUpdates take two parameters( winners and lossers). Now i need add new ...
3
votes
3answers
2k views

Implementing the Interface Segregation Principle

Does this IConvertible interface satisfy the Interface Segregation Principle (ie. the "I" in SOLID)? Here is the definition: public interface IConvertible { TypeCode GetTypeCode(); bool ...
0
votes
3answers
509 views

Interface properties implementation

As the code below, class Foo1 implements interface IFoo, which has a property of IData. public interface IFoo { public IData Data { get; set; } } public interface IData { ... } public class ...
2
votes
2answers
144 views

Does it make sense to implement a Class Factory design in an RPG Character Creation module

I'm a self-taught Engineer, a beginner in Java and I am trying to create a Dungeons and Dragons character creation module for a bigger game to solidify my understanding of core concepts while learning ...
0
votes
3answers
133 views

How to structure a set of classes that deal with external APIs for maximum testability?

I'm developing a set of classes designed to communicate with external APIs, and I'm running into trouble with how to properly structure everything for proper loose coupling and unit testing. ...
8
votes
5answers
508 views

What core principles would you want in a library?

Theres talk about what syntax and feature you like in a programming language; i'll now ask what core principles or feature would you like in a library in your favorite (or any) language? An example ...
1
vote
1answer
98 views

Handling multiple game modes with a game controller

I have a basic GameController with a finite state machine to handle game logic. I'm adding game modes and coming across problems cleanly implementing them. The core functionality of the game stays ...
1
vote
2answers
85 views

In some IOC contexts, could constructor of polymorphic immutable object be required in its interface?

Generally, constructors in an interface are considered as being an anti-pattern. Some languages even don't allow that. Then I don't understand how we're supposed to deal with polymorphic immutable ...
1
vote
1answer
120 views

Is it a good design to create an interface that inherits from multiple interfaces to reduce the amount of dependencies of a client?

I was refactoring an application to respect SOLID principles. When I was applying interface segregation I found the following case: interface A { void methodA(); void methodA2(); } ...
0
votes
4answers
1k views

Avoiding vtable pointers in objects in C++

In my previous question, it was highlight that implementations of C++ such as GCC must store a vtable pointer in every copy of a class for each parent class which has a virtual function. So a class ...
1
vote
5answers
356 views

How to avoid the continuous downcasting in this case?

I have an abstract class Dog and multiple subclasses (Beagle, Labrador, Bulldog...) extendig it. I have a DogHouse that can store a Dog. My problem is that when I put for example a Beagle into a ...
1
vote
1answer
814 views

Using generics on interfaces when implementation is not generic

Is it acceptable practice to put generics on an interface when the implementation will not be generic? Lets say that my project will have many classes that read data from the database. I may make a ...