Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
5
votes
3answers
278 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 ...
2
votes
1answer
150 views

What are Java Interfaces used for? (multiple choice question)

I'm a beginner studying interfaces in Java through some quizzes and I came through this question: What are Java Interface used for? I can opt among one of the following three choices: A. They'...
3
votes
5answers
133 views

User stories about one and the same functionality for two different roles

My team is building a solution where a mobile app communicates with a backend. I need to describe functionality where the communication between the app and the backend is optimized according to some ...
5
votes
1answer
127 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, ...
-1
votes
2answers
77 views

How to implement a different behaviour for a method without changing the interface?

I am creating a small project that implements an interface in Java. I am not allowed to modify the interface, which means I can't change the functions in my class that implements the interface. ...
1
vote
2answers
103 views

Why can't I use a generic method to implement multiple typed interfaces in C#?

public class B { } public class C { } public class D { } public class E { } public class A : IRetrievable<B, C>, IRetrievable<D, E> { public TValue Retrieve<TKey, TValue>...
1
vote
1answer
69 views

Decoupling from third party library

I'm doing a project in PHP and I'm implementing Aggregates and Event Sourcing. In order to avoid coding up all the logic related with ES myself I've decided to use a third party library called ...
3
votes
3answers
276 views

Fruit obj=new Orange(); and Orange obj=new Orange(); if both works identically in my code, which is the less coupling one?

Suppose I have 2 classes (which don't show methods to look simpler): public interface Fruit{ } public class Orange implements Fruit{ } , and assume I can use 2 ways to initialize Orange without ...
0
votes
0answers
21 views

Succinct API design for supporting both Push and Pull-style Stream operations

I have a C# interface that represents an image-file (photo, logo, etc) that's been loaded into memory. I have different implementations (using System.Drawing, ImageMagick.NET, test stubs, etc) - a ...
-2
votes
1answer
93 views

Design a generic hardware interface

I am trying design a generic hardware facade interface for different camera types. below is my incomplete generic interface for camera devices template <class Data,class Configuration> class ...
1
vote
1answer
72 views

Operand ordering for matrix multiplication with assignment

If you have a matrix class with overloaded operator*=, which order should the operands be placed for the interface to be useful and intuitive. One can choose A *= B to be equivalent to either A = A*B, ...
2
votes
4answers
219 views

Iterating through objects with slightly different interfaces

I am constructing modular logic for my object: separate pieces of functionality are going to separate modules. I will have the ability to connect and disconnect modules on demand. At some point my ...
2
votes
2answers
145 views

How to design different moves of different pieces of a Chess game using OOP principles?

I am trying to design a Chess game where each piece of the game inherits from an abstract Piece class. The piece just does a few things: It tells which color it is (White / Black) It tells what type ...
34
votes
7answers
9k views

Should I still follow “programming to an interface not implementation” even if I think using concrete class members is the simpler solution?

According to Understanding "programming to an interface", as I understand, I think I should depend on abstract class only. However, in some case, for example, Student: public class Student {...
27
votes
8answers
8k views

In C#, is there a way to enforce behavior coupling in interface methods or is the fact that I am trying to do that a design smell?

Many times I want to define an interface with some methods that maintain a behavior relationship between them. However, I feel that many times this relationship is implicit. With that in mind, I ...
3
votes
1answer
110 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 ...
2
votes
1answer
120 views

How to properly decouple using interface

I have a ecosystem simulation where animals move and collide with each other. Here is how I handle collisions: public void HandleCollisionBetween(Animal a, Animal b) { if (a.GetType()....
2
votes
1answer
131 views

Human and AI subclasses for Player class

I am looking to implement two branches of classes in my Java program to distinguish between Human and AI-controlled Players in my game. The game is asynchronous, so players have different methods and ...
1
vote
5answers
305 views

When should i use an abstract class vs an interface? [duplicate]

I'm fairly new to programming. At school I am currently learning to program with Java. I want to build an application where i can store my collection of books, records, boardgames and such. Started ...
1
vote
1answer
64 views

Modeling objects that behave in different ways so that they can be stored in a collection?

Suppose I have a Player class with an Inventory: public abstract class Player { private final List<GameObject> gameObjects; public Player(){ this.gameObjects = new ArrayList&...
0
votes
4answers
303 views

OO-question re: interfaces and is-a vs. has-a

Disclaimer: the following is written without further distinction in the object oriented terminology as C# is implementing it: classes, interfaces and instances, etc. Let's assume the following ...
0
votes
3answers
134 views

How to properly apply open/closed principle on large code base for apparently unrelated features

Let's say I have a class hierarchy like this: Now let's suppose I add later a new interface Mechanic, responsible for repairing a vehicle. Of course someone capable of repairing a car won't fix your ...
1
vote
1answer
95 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
549 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
2answers
218 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 ...
0
votes
3answers
79 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
255 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
179 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
72 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
160 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 ...
5
votes
1answer
749 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
117 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
101 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 ...
2
votes
1answer
117 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 ...
0
votes
3answers
97 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
19 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) ...
0
votes
2answers
362 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
1answer
233 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 ...
1
vote
4answers
231 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
469 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 ...
2
votes
3answers
488 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 ...
1
vote
1answer
324 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 ...
2
votes
1answer
178 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:...
3
votes
3answers
555 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
130 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
373 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 ...
0
votes
3answers
95 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
304 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
100 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) ...
0
votes
1answer
1k 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 ...