Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
7
votes
3answers
331 views

SOLID, Does Liskov Substitution Principle (LSP) conflict with the Interface Segregation Principle (ISP)?

I am confused by the two principles of SOLID, liskovs substitution principle and interface segregation principle. It seem as though they conflict each other's definitions. How can a class that ...
0
votes
1answer
47 views

Architecture Layers - Interface project at the top

We have structured our application with typical layers. UI, Database access, services, Helpers etc. However, at the very top we have a project called "Interfaces" which contains the ...
1
vote
4answers
440 views

Why is an interface in Java called an “interface”?

I am not sure why an interface in Java is called an "interface", but I think it can be one of the following two reasons (or both): Reason one: This tutorial says the following: Methods form ...
1
vote
2answers
171 views

Is there a statically typed programming language that implements Polymorphism without using a superclass or an interface?

Is there a statically typed programming language that implements Polymorphism without using a superclass or an interface (if such implementation is even possible)?
-5
votes
1answer
116 views

What is the point of interfaces and abstract classes? [closed]

So I'm taking a course on java programming, and in the lesson about interfaces, they gave an example of an interface with a Bird class, along with Chicken and Sparrow subclasses that extend Bird. They ...
0
votes
2answers
115 views

Encoding const-ness on interfaces. Readers - Writers vs Const wrapper

This question is based on this separate question on stack overflow. I have a very low-level structure meant to compactly save presets on flash memory. For simplicity I am going to use stored_record as ...
0
votes
1answer
98 views

What is a not well-defined interface?

I keep reading about "well defined interfaces", as here, here or here, specially when talking about microservices. What's an example of the opposite, an interface that is not well-defined?
-3
votes
1answer
111 views

What's the argument against complex type hinting in interfaces in PHP?

The more I write OOP, the more I realize that besides reasoning & structure, there isn't much for me and things make more sense if I combine that with functional or just straight-up non-OOP. Not ...
-4
votes
1answer
52 views

Should I use interfaces in Python (so my code will be more testable and following good practices)?

I've never coded in Python. In languages like C# or Java a lot of people write interfaces for (almost) every class so the code can be more easily testable (by implementing IoC) or other reasons and is ...
4
votes
3answers
155 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::...
3
votes
3answers
181 views

Java interface design: where should I put a lot of duplicate code that will be used by all subclasses?

Java interface design: where should I put a lot of duplicate code that will be used by all subclasses? interface Tuple { void method1(); } class Tuple1 implements Tuple { @Override public ...
-2
votes
3answers
74 views

Behaviour that depends on two sides

I would like to have the following interface: Resource { public: void copyInto(Resource* src) = 0; } But in order to implement this, the implementation would need to know (or make assumptions about) ...
1
vote
3answers
142 views

What does Combinatoric Interface mean?

I am watching this talk by Sean Parent. He notes that: Choosing the same syntax for the same semantics enables code reuse and avoids combinatoric interfaces What does "combinatoric interface" mean?...
1
vote
1answer
44 views

Where to handle duplicate key exceptions in multy layer application

+-------------+ +--------+ +----------+ | repository +-------->+service +------->+controller| +-------------+ +-^------+ +------------+ +-------------+ | ...
1
vote
2answers
85 views

What goes on behind the scenes when data is passed through the use of interfaces?

I understand an interface is a contract and if a class implements that interface, it must define those abstract methods from the interface. What I don't understand is, how is data passed between two ...
2
votes
1answer
100 views

Is it allowed to include the composition in the compositor in the Strategy Pattern

I have a range of different animals in my zoo such as turtles, birds etc. As they all share a common trait such as either swimming, flying etc., I thought a strategy pattern would be appropriate to ...
5
votes
0answers
103 views

Fortran-Python Interface

Disclaimers: This question is reposted from SO upon SO user's suggestion to put it here since there is no specific code in question. This question is a subset of my larger theme of Fortran ...
3
votes
1answer
82 views

Issues with an interface treating a synchronous action as async

Let's say I'm trying to write a library that abstracts certain actions. In this example I want to turn a light on or off. There could be hundreds of different kinds of lights that are controlled in ...
1
vote
2answers
94 views

Is it a best practice or anti-pattern to export mock versions of functions for a library?

Context We are creating a library that makes an API (HTTP) request to a 3rd party. During testing we have written mock versions of the functions that make external requests so that we can test the ...
3
votes
1answer
57 views

Golang Interface Design for Multiple Parameter and Return Types

General question how can I design an interface that can support both // v1beta1.Deployment type Deployment struct { metav1.TypeMeta metav1.ObjectMeta Spec v1beta1.DeploymentSpec ...
0
votes
6answers
130 views

Adding client specific method to a listener interface is a good idea?

I'm using a listener pattern where a class A listens for events from various classes B, C, D with the help of a listener interface I Essentially the structure looks like: interface I { void ...
0
votes
1answer
122 views

Name of this enum-based design pattern to get the type

I have been using a pattern in a lot of places (mainly C#) that I would like to know the name of. Here is an example of it in C#: public enum ThingType { A, B, C } public interface ...
1
vote
0answers
33 views

subinterfaces redeclaring abstract methods

Why is it that some abstract methods in interface hierarchies are redeclared as abstract further down? iterator() for example, abstract in Collection is redeclared in Set and List, and again further ...
1
vote
0answers
122 views

How to design the interface method for the following case?

I am making an SNMP agent. In order to pass information to this SNMP agent, I need to periodically extract data from two different sources (and there may be more sources in future.) I am trying to ...
1
vote
1answer
74 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
355 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
333 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; } ...
59
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
153 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
508 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 ...
5
votes
2answers
252 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
257 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
431 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
181 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're ...
3
votes
5answers
146 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
142 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
92 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
234 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
92 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
304 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
26 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
98 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
77 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
235 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
164 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
10k 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
234 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
123 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()....

1
2 3 4 5
13