Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
1
vote
0answers
61 views

How to design the interface method for the following case?

I am making a Snmp agent. In order to pass information to this Snmp agent I need to periodically extract data from two different sources and there can be more sources in future. I was designing the ...
4
votes
5answers
1k 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, ...
1
vote
1answer
65 views

Can this simple Bank example be considered as a valid Abstract Factory?

For teaching purposes, I'm trying to replicate in a more faithful way from this conceptual UML (from wikipedia): In a "so-so" real world example, in my case, families of Loans and Insurances: So, ...
4
votes
4answers
296 views

Do we really need interface classes for the dependency inversion principle?

As a practical example, imagine a Gripper class which represents a robotic gripper in a simulation. Gripper has a TryGrip method, which checks if there's a GrippableItem in the correct position (...
3
votes
4answers
295 views

Do “avoid primitive obsession” and “use most abstract type as possible” contradict each other?

According to Is "avoid the yo-yo problem" a valid reason to allow the "primitive obsession"?, I should define "price" like this: public class Main{ private Price price; } ...
4
votes
1answer
520 views

The inheritance argument of zope.interface (providedby vs isinstance)

What limitations does inheritance of an interface through an abstract base class present that are addressed by zope.interface? In the following talk given in 2010 by Jeff Rush about interfaces, at 11:...
57
votes
8answers
9k views

How do I ensure that interface implementations are implemented in the manner I expected?

Let's say there is a member SomeMethod in an interface ISomeInterface as follows: public interface ISomeInterface { int SomeMethod(string a); } For the purposes of my program, all consumers of ...
3
votes
1answer
86 views

Does it make sense to apply interface segregation to a facade?

In my project, we have a couple different back-end APIs/endpoints that are called by the same front-end page at different times. All of these endpoints are sort of related to the overall "theme" or "...
2
votes
4answers
478 views

Unnecessary (?) ReadOnly fields in Interfaces

Under the context of dependency injection - that is, an interface has mostly one implementation - I took the habit of exposing via the Interface a bunch of fields which are never called by the ...
2
votes
5answers
3k views

C# How to avoid duplicate code with interfaces where objects have the same behaviour

So a simple example i have: public interface IFollow{ Transform Target {get;} void LateUpdate(); } public A : Monobehaviour , IFollow { public Transform Target {get; set;} public void ...
5
votes
2answers
218 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 ...
13
votes
3answers
5k views

How does encapsulation actually work?

I made the following diagram to show a typical separation of concerns as typically taught - Here ClassA indirectly uses ClassB via the ISomeInterface, of course ensuring it doesn't know ClassB exists,...
2
votes
2answers
167 views

C# - Correct way to convey Null Object design pattern via an interface for client/service?

I've just learnt about the Null Object design pattern, which recommends that the service either return a default null object or throw an null related exception itself so that the client need not worry ...
5
votes
3answers
339 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
172 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
142 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 ...
15
votes
6answers
15k views

Can I consider interface methods as abstract methods?

I was thinking about that, and I had some doubts. When I declare an interface, for example: public interface MyInterface { public void method1(); public void method2(); } Could these ...
5
votes
1answer
136 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
83 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
108 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
74 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 ...
14
votes
5answers
4k views

Using Func instead of interfaces for IoC

Context: I am using C# I designed a class, and in order to isolate it, and make unit testing easier, I am passing in all its dependencies; it does no object instantiation internally. However, instead ...
1
vote
1answer
312 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 ...
3
votes
3answers
290 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 ...
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 {...
2
votes
4answers
223 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
1answer
95 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
73 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
2answers
152 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 ...
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 ...
17
votes
4answers
26k views

How to best to organize class and interface files?

OK .. after all the discussion I'm changing my question slightly to better reflect a concrete example that I am dealing with. I have two classes ModelOne and ModelTwo, These classes perform ...
107
votes
6answers
70k views

What is the point of having every service class have an interface? [duplicate]

At the company I work at, every service class has a corresponding interface. Is this necessary? Notes: Most of these interfaces are only used by a single class We are not creating any sort of ...
3
votes
1answer
113 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
121 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
139 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 ...
0
votes
4answers
305 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 ...
1
vote
5answers
370 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 ...
0
votes
2answers
4k views

How to use namespaces to separate interface from implementation, in c++?

As far as I can tell, you can make your interface known to others by providing your .h file. Your .cpp is the implementation. Then they can see the function names, the parameter types, the return ...
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
3answers
135 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
108 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
553 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
225 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
278 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
223 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
119 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
164 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 ...

1 2 3 4 5 13