Questions tagged [interfaces]

Questions about `interface` related design considerations, and also "programming to the interface instead of the implementation"

Filter by
Sorted by
Tagged with
2 votes
3 answers
334 views

Should my methods return concrete classes or interfaces?

I'm building a ASP.NET Core Web API and the application consists of 3 main modules. Data module: Contains the entities and DbContext Web API: Contains the controllers Service module: Contains all the ...
Yashoja Lakmith's user avatar
3 votes
4 answers
443 views

Does "declare the most abstract type" increase coupling actually?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, so for example: public interface Fruit{ }...
wcminipgasker2023's user avatar
1 vote
1 answer
101 views

Virtual Method vs. Abstract Class Member

Suppose we are writing an interface class which has some "properties" and "operations." Assume also that every concrete implemented of the interface must contain the same set of ...
Patrick Wright's user avatar
0 votes
4 answers
274 views

Are "easier to search for the interface" and "avoid yo-yo to interface to find implementations to fix bugs" reasons to add prefix "I" on interfaces?

According to Should interface names begin with an "I" prefix?, I should not add prefix "I" to interfaces. However, I think prefix "I" in interface may be useful sometimes....
wcminipgasker2023's user avatar
1 vote
3 answers
197 views

How robust should an interface/implementation be?

In a spare-time project of mine, I implemented RSA public-key cryptosystem. Because the official PKCS#1 standard specify key formats in terms of ASN.1 syntax and DER/BER coding, which is a coding with ...
DannyNiu's user avatar
  • 181
0 votes
2 answers
172 views

For non-container classes, are "better naming" and "ready for commented codes" good reasons not to declare the most abstract type?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, but the question is about template class ...
wcminipgasker2023's user avatar
0 votes
1 answer
48 views

Where to store a props type declaration on a DDD project?

I am trying to apply DDD to a Vue project (so it's DDD on the frontend) and I have a doubt as to where store a props type. A Vue component can have props, which is basically named data passed to the ...
Bernardo Benini Fantin's user avatar
1 vote
1 answer
80 views

Correct way to represent acquaintance enforced by interface in UML class diagram

Suppose I have the following client code: using System; namespace InterfaceCompositionUml { internal class Program { static void Main(string[] args) { ...
user32882's user avatar
  • 267
0 votes
1 answer
81 views

Why aren't mandatory options requested in the signature of ASP.NET Core "AddXXX" methods?

I've developing a .NET Core library meant to simplify the configuration of the authentication within our SSO system. It will expose two methods to be called in the Program.cs (or Startup.cs) of ASP....
Gua-naiko-che's user avatar
0 votes
1 answer
242 views

Interfaces vs abstract classes for immutable DTOs

At my org we extensively use @Value.Immutable annotation to generate Immutable classes (usually with builders) for our internal data transfer objects (DTOs). In our codebase I've seen both interfaces ...
y2k-shubham's user avatar
1 vote
1 answer
77 views

Is there a way to introduce some basic type safety around IntPtrs returned from PInvoke'd methods?

I have a C-Style API with methods that return pointers to native objects, e.g. EXPORT hs::Pose3d* getJointEndPose(dh::Joint* joint); And in C#, [DllImport("Solver.dll")] public static ...
sebf's user avatar
  • 285
0 votes
0 answers
79 views

Const correct interface for non-mutating function that returns mutable references into data structure

I very much want my code to be const correct and I'm struggling to get the following case right. Say we have a function F that takes a data structure D and computes an auxiliary data structure D'. F ...
chrysante's user avatar
  • 127
2 votes
1 answer
325 views

How to implement interface on Java class I don't own?

I want to allow some Java objects to be translated into a string representation which matches Python or JavaScript objects. I thought that I could tag all compatible classes with compatibilising ...
theonlygusti's user avatar
2 votes
1 answer
224 views

How are interfaces implemented behind the scenes in the Go language?

I have read this article which indicates a double tuple structure, but it is unfortunately light on implementation details, which is what I am looking for. So... how are interfaces implemented in Go? ...
SRNissen's user avatar
  • 151
0 votes
0 answers
109 views

SQL Database design for reusable components and classes

I am working on a small suite of enterprise applications, and I am trying to determine the best way to make them more consistent and maintainable across the board. The applications are .Net Blazer ...
aterbo's user avatar
  • 111
1 vote
2 answers
192 views

It is okay to create an interface of interfaces?

Let me first describe the situation I have a component that uses dependency injection through a service locator. In the first scenario (image 1) the component needs a class that implements Interface0, ...
DanielJaramillo's user avatar
0 votes
2 answers
98 views

Where to check preconditions in multi functions

In a library, there could exist three types of functions. The first are those which are visible to the user i.e. their declarations are installed in the library's include directory. The third are ...
Nitin Malapally's user avatar
1 vote
1 answer
173 views

Gradle/Maven project splitting: interfaces and implementation

Assume we have a single large JVM project (the example is in Kotlin), containing code. As part of a refactoring effort, we are decoupling pieces of the code by splitting the code into multiple modules,...
Hidde's user avatar
  • 170
0 votes
1 answer
79 views

How to seamlessly interact with a message broker when the underlying system (SQS, RabbitMQ) can change depending on the environment?

Having a poor knowledge of the extended features of the available message brokers, I was wondering how to approach this. We have some environments where only RabbitMQ is available, others where ...
kant312's user avatar
  • 111
-2 votes
2 answers
281 views

How does injecting a concrete class expose implementation? [duplicate]

I've read that you should pass in an interface instead of a concrete implementation so that the consumer doesn't need to know anything about implementation details. I don't understand how injecting a ...
james's user avatar
  • 113
1 vote
1 answer
138 views

Refactoring instanceOf, moving logic to POJO when it has database interaction

I'm refactoring some old code, I have a lot of istanceOf in the business part: if (record instanceof RecordA) { RecordA recordA = (RecordA) record; ...
Accollativo's user avatar
0 votes
1 answer
200 views

Exposing only the getters of a singleton interface in C++

I've got a file in my includes folder, which is the folder I expose, that isn't used externally and isn't supposed to be used too. When I noticed that and tried to remove it - I noticed that it's ...
RedYoel's user avatar
  • 123
0 votes
2 answers
322 views

How to create an interface in C that can work on two identical structs with differently named fields

Question Background Consider a scenario in which I have two structs. Both consist of three fields for doubles. The only difference is the names used to refer to these fields. The first struct is for ...
Shadow43375's user avatar
1 vote
2 answers
140 views

physical simulation: design thoughts

I'm an applied physics student and currently working on a simulation of the magnetic interactions of multiple protons within a protein. Me having only little experience with programming and almost ...
Meck3l's user avatar
  • 17
4 votes
3 answers
917 views

What is the relationship between variance, generic interfaces, and input/output?

There is a blog post by Eric Lippert where he describes how to define variance. In a general sense, covariance is achieved when the direction of assignment compatibility is preserved. Contravariance ...
Ramza's user avatar
  • 51
2 votes
2 answers
392 views

Can access modifiers be completely replaced with programming to interfaces?

If we program to interfaces various parts of the implementation can be effectively hidden. We can define multiple interfaces for a single implementation and use them as needed, instead of 4 fixed ...
Ondrej Bozek's user avatar
0 votes
3 answers
859 views

How to handle a new method in the interface that is not applicable for all classes?

I am faced with an interesting OOD problem: I have an interface with 3 methods: interface TestInterface { String action1(); String action2(); String action3(); } and 3 classes that ...
Zed's user avatar
  • 117
0 votes
3 answers
773 views

Which Clean Architecture Areas do Gateways interfaces and their implementations belong to?

Talking about gateways from the Clean Architecture, it is required to distinguish: The interfaces The implementation of these interfaces The TypeScript example: // === Interface =====================...
Takesi Tokugawa YD's user avatar
2 votes
1 answer
234 views

Interface segregation principle

Let's say we have the following business requirements: We have a list of dishes. They have a name and a list of ingredients. The restaurant owner always wants to have a dish (and only one) marked as ...
Antonio Gamiz Delgado's user avatar
29 votes
3 answers
10k views

Is it Good Practice to Only Expose Interfaces

I''m working on a C# library where the API provides several public interfaces and a single concrete factory class (itself an interface implementation). This factory provides implementations of the ...
Bondolin's user avatar
  • 403
0 votes
4 answers
5k views

DI: Injecting interfaces vs actual classes

In my job I work with C# (although the language is irrelevant for my question, and now I'd like to focus on Android) and we usually inject interfaces and not the actual classes, so I was wondering ...
Diego Perez's user avatar
16 votes
7 answers
4k views

Where should interfaces be used?

One thing I've long struggled with being able to grasp properly is, when designing a program in an object-oriented language, where and how should explicitly named/defined interfaces be added? In ...
The_Sympathizer's user avatar
6 votes
2 answers
1k views

Naming an interface that does something and its opposite

Maybe I'm overthinking about naming, but it's a problem I've encountered several times and it was really annoying every time. I have three interfaces. The first is IAssembler, which has assemble(...) ...
Bipolo's user avatar
  • 83
0 votes
2 answers
729 views

What are the tradeoffs between a Union type or a wrapper Class to represent a formatted string argument representing multiple types

Assume there's a public void process method on a Java class called A that currently takes a single String argument id. class A { public void process(final String id) { // Some implementation } ...
Jae Bradley's user avatar
-1 votes
1 answer
294 views

How to apply the Open-Closed design principle for different parameters in each class

I am a noob in design principles and design patterns, this might seem like a very silly question. Some classes in my code have the following structure (image linked): https://ibb.co/nrp1t2g As you can ...
Shuaib's user avatar
  • 99
3 votes
1 answer
421 views

C++ Abstract classes vs selective compilation

I'm trying to find a way to achieve abstraction with the lowest possible overhead. This is for an embedded system (Cortex-M4), I use the latest gcc compiler arm-none-eabi. Let's say we have a pure ...
ProgrammingPort022's user avatar
0 votes
2 answers
1k views

Golang interface-implementation circular dependency

In trying to separate interface from implementation, I ran into a circular dependency problem. There is a best practice in the world of Java: consume interfaces instead of concrete classes. That is, ...
selamba's user avatar
  • 109
2 votes
2 answers
133 views

Use of internal interface around paid APIs

Note: I'm new to using paid APIs (like Stripe, GPT-3, Twilio, ...). When you are using a paid 3rd-party API, you are essentially betting on them keeping reasonable prices in the future, right? So in ...
Moritz Groß's user avatar
1 vote
0 answers
70 views

Create Views depending on the dynamic type of an object returned by the model in MVP

In my MVP app, my model (a service) returns a collection of ISession pointers. Each pointer points to an object of a derived type HttpSession or HttpsSession. The model (the service) knows nothing ...
JenyaKh's user avatar
  • 111
0 votes
4 answers
355 views

Adapter or pure interfaces?

I got a bit strange 'future ready' scenario. And I'm not sure if I got it right in regards to C# adapter design pattern. The scenario is that to be future ready, 'to use the adapter pattern' to easily ...
Peter's user avatar
  • 137
0 votes
3 answers
522 views

Composite Pattern get part of the tree

I use java and I have structure with a class that contains id, title and perhaps some children of the same class. So I decided to use the composite pattern. I need to have a method getChildren() that ...
Christoforos's user avatar
0 votes
2 answers
132 views

Make date range generator interface stateful or stateless?

An app has a feature that's much like any calendar application (like the Outlook calendar for example). Consequently, I need to do a lot of date logic. I wrote a class with date calculation methods ...
user2190492's user avatar
2 votes
3 answers
2k views

Should you use interfaces or classes in database entities?

Let's say I'm making a library database with books and authors, and I want to model the domain with interfaces, should I also specify the relations in the interfaces? For example, if I have the ...
JansthcirlU's user avatar
0 votes
1 answer
2k views

Where should interfaces/model definitions live? -- Clean architecture

I'm working on a Node project (in typescript) that features a variation of clean architecture. I have a pretty clear understanding of the different layers of an application and how they depend on each ...
GHOST-34's user avatar
  • 111
1 vote
1 answer
453 views

Are there reasons why I shouldn't put a cpp file in my interface?

It is quite common to separate C++ code into cpp and hpp files and to define the hpp files as the interface of the code. Therefore, when you use the code as a library, you can expose the interface, ...
Cerno's user avatar
  • 113
2 votes
5 answers
999 views

Class method Vs. Interface?

I am relatively new to C# and OOP concepts in general, but am building a standalone application and have run into a question and want to make sure I'm doing it the "right way". I have a few ...
adc395's user avatar
  • 39
-1 votes
1 answer
178 views

Should I use a database as gateway to other services? [closed]

The context I have an IoT project where the sensors are sending data to my Postgres database. The sensors are manages by a stand-alone service which provides a REST API to query various information ...
Eerik Sven Puudist's user avatar
1 vote
3 answers
182 views

Extracting interface or use double dispatch to avoid downcasting?

Here's an analogy of our concrete problem to demonstrate the issue at hand. We need to manufacture cars, with either petrol or diesel related parts (the parts can be the engine and the exhaust - e.g. ...
Chris's user avatar
  • 161
-2 votes
3 answers
567 views

Singleton as Interface for testability via dependancy injection

It can be found in many advices on topic that having Singletons is an anti-pattern. Especially for cases of testability. Can someone please advice/critique on this way (please see code below) of ...
psb's user avatar
  • 101
1 vote
4 answers
562 views

Is casting between interfaces the best approach for capability discovery when using interface inheritance?

It’s frequently taught that downcasting is bad practice. I have a case where it seems necessary, but I’m wondering if there is an alternative way to design this. Suppose interfaces are kept small ...
justin's user avatar
  • 49

1
2 3 4 5
15