Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
-3
votes
0answers
23 views

How to program P-L496G-CELL02 discovery kit to receive data over SPI and transmit it to the cloud over the NBIOT channel? [on hold]

The P-L496G-CELL02 comes with the 32L496 discovery board, stmod+ add on, and Quectel's BG96 module. https://www.st.com/en/evaluation-tools/p-l496g-cell02.html#tools-software New to programming with ...
1
vote
1answer
55 views

Depend on DDD Entities or Interfaces?

My understanding is that the dependency inversion principle does not apply to entities, because entities basically are your application - it generally doesn't make sense to swap out a different ...
2
votes
6answers
452 views

What SOLID principles am I breaking with this code?

With the below pseudo code? Am I breaking any SOLID principles? interface i_pet string get_name() string get_species() color get_fur_color() end interface interface i_cat implements i_pet end ...
0
votes
0answers
39 views

Are there any (recommended) ways to refactor around passing the same object for multiple parameters of a method/constructor? [on hold]

I am having a class implement two (or more) separate interfaces: public class Demo : IInterface1, IInterface2 { ... } Then at some point, I need to call a method (or constructor) depending on ...
0
votes
2answers
189 views

Interface/Contracts in separate assembly?

Say I have BusinessService & domain logic as part of MyProj.MiddleTier csproj which connects to MyProj.DAL DataRepository via interface IDataRepository. I am using IOC unity container to build my ...
1
vote
1answer
248 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 ...
0
votes
3answers
74 views

Should a composition be considered a resource in REST?

Consider this example system consisting of the following resources: Family, Person and Role. A Family and Person has a many-many relationship and each family member has a certain "role". For example, ...
0
votes
3answers
191 views

Is there any advantage using generic type which implements interface over direct interface usage?

When I was looking this question, a question comes my mind. Think about using an interface like : public interface ICommandProcessor<T> where T : ICommand { void Process(T command); } ...
0
votes
1answer
83 views

In a Spring Boot Project, would you use interfaces for entities or not?

I am currently on the decision, whether to use interfaces throughout my whole spring project or not. I scouted some open source projects and saw, that many big projects are handling that quite ...
0
votes
1answer
69 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
100 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
150 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
740 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
112 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
80 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
94 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
154 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
169 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
481 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 ...
239
votes
15answers
102k 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
225 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
389 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 ...
10
votes
8answers
960 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
182 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
525 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
171 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
7k 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
92 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
221 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
286 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
265 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
99 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
493 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
692 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
139 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
292 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
203 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
90 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
89 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
632 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
146 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 ...