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
0 votes
1 answer
39 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
0 votes
0 answers
39 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
  • 255
0 votes
1 answer
77 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
141 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
75 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
77 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
  • 129
2 votes
1 answer
315 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
207 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
  • 145
0 votes
0 answers
93 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
188 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
91 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
138 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
67 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
223 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
118 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
183 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
  • 103
0 votes
2 answers
269 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
135 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
858 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
375 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
561 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
2 answers
627 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
228 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
28 votes
3 answers
9k 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
  • 393
0 votes
4 answers
4k 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 TheGod's user avatar
0 votes
2 answers
562 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
267 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
383 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
968 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
69 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
317 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
451 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
128 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
389 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
938 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
171 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
178 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
489 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
449 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
2 votes
2 answers
281 views

What are some alternatives to translate data models in C#?

I have a need to translate data from provider A to provider B. The data is typically pretty consistent, but, often has minor differences; for example: public sealed class ProviderOneFoo { public ...
Hazel へいぜる's user avatar
2 votes
4 answers
1k views

Confused about inheritance and correct usage. Should I avoid using members in base class?

I am using C++ , but as far as I understand most OO principles are cross language. In most of the articles that I have read and liked about inheritance the advice are about : not to use it for the ...
user3717741's user avatar
22 votes
11 answers
5k views

In a fluent interface with "with", is cloning expected?

In an object oriented language like Java or PHP (other perspectives welcome as well) if I use a fluent interface like this: my_pizza = (new Pizza).withTopping("pineapple"); another_pizza = ...
AndreKR's user avatar
  • 577
0 votes
1 answer
845 views

How to expose C++ static library interface, extending Pimpl to an abstract interface

Until today I had a static C++ library with no separation between the public interface and internal headers. My other apps just linked to it, included the required headers, and used whatever they ...
user3717741's user avatar
2 votes
3 answers
159 views

Java design: there is two interface: B extends A. A and B have one subclass each, named ABase and BBase, can I make BBase extend ABase?

there is two interfaces A and B: public interface A { } public interface B extends A{ } A and B have one subclass each: public abstract class ABase implements A{ } public abstract class BBase ...
Guo's user avatar
  • 177
1 vote
1 answer
132 views

How do I "code to an interface, not an implementation" with third party objects?

I have an interface public interface MovieDataFetcher { List<Movie> fetchAll(String query); } And these concrete classes public class ImdbDataFetcher implements MovieDataFetcher { ...
Karl S.'s user avatar
  • 121

1
2 3 4 5
15