Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
0
votes
2answers
1k views

Using interfaces as part of encapsulation

I'm creating interfaces for a number of our existing classes for mocking reasons. Many of these classes also have package scope methods as an attempt to give some level of encapsulation by ensuring ...
6
votes
1answer
30k views

Difference between spring setter and interface injection?

I know how constructor and setter injection works in spring. Normally I use interfaces instead of classes to inject beans using setter and I consider it as interface injection, but in case of ...
1
vote
3answers
140 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?...
6
votes
9answers
2k views

Does it make sense to declare private fields using an interface as their type?

For the fields that you have as encapsulated members of a class, does it make sense to declare their type to be of the interface that you are using? For example: public class PayrollInfo { private ...
1
vote
1answer
43 views

Where to handle duplicate key exceptions in multy layer application

+-------------+ +--------+ +----------+ | repository +-------->+service +------->+controller| +-------------+ +-^------+ +------------+ +-------------+ | ...
3
votes
1answer
81 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
80 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 ...
1
vote
1answer
365 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 ...
2
votes
1answer
98 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
97 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 ...
7
votes
6answers
2k views

How do large engineering teams describe the interface/contract between a web service and client JavaScript code? [closed]

I'm looking for a formal way for a front-end and a back-end team to communicate on the shape of a JSON web API. For example, let's say you are on a client-side team writing the JavaScript & HTML ...
1
vote
2answers
88 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
205 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 ...
36
votes
9answers
28k views

Default vs Impl when implementing interfaces in Java

After reading Should package names be singular or plural? it occurred to me that I've never seen a proper debate covering one of my pet peeves: naming implementations of interfaces. Let's assume ...
0
votes
6answers
129 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 ...
34
votes
11answers
19k views

Why does PHP have interfaces?

I noticed that as of PHP5, interfaces have been added to the language. However, since PHP is so loosely typed, it seems that most of the benefits of using interfaces is lost. Why is this included in ...
3
votes
1answer
51 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
1answer
120 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 ...
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
70 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
338 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
319 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
541 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:...
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
126 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
497 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
4k 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
236 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
220 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
388 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'...
3
votes
5answers
144 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
140 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
91 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
164 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
85 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 ...
15
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 ...
3
votes
3answers
301 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
24 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
229 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
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
76 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
159 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 ...
20
votes
4answers
29k 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 ...

1
2 3 4 5
13