Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
1 answer
114 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 ...
-1 votes
1 answer
71 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 ...
17 votes
6 answers
15k views

What are the differences between abstract classes, interfaces, and when to use them

Recently I have started to wrap my head around OOP, and I am now to the point where the more I read about the differences between abstract classes and interfaces the more confused I become. So far, ...
0 votes
2 answers
105 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, ...
4 votes
1 answer
229 views

What do you call the interface design error that consists in splitting two public methods that should be called together?

Consider a poorly-designed interface in which there are two functions (say foo() and bar()) that can be called independently, but in order to get some expected behavior (or in order to keep the object ...
2 votes
2 answers
122 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 ...
0 votes
0 answers
25 views

How to keep in sync definitions of exchange data

I am a single, amateur developer and I am currently learning on a server (Golang) and client (TypeScript, Vue) application. The client calls the server through a REST-like interface and exchanges a ...
1 vote
0 answers
45 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 ...
14 votes
4 answers
26k views

Writing 'interfaces' for static classes

I'm writing a postcode validation library, so that I can call a helper method var result = Postcode.IsValid(postcode, country) To that end I need to have 'classes' that represent supported countries ...
-1 votes
2 answers
145 views

Does accepting a handler instead of returning a result have a name?

def create() -> socket.socket: ... return sock def create_(func: callable)-> None: ... func(sock) return What are the names of those two interfaces between* a socket ...
0 votes
4 answers
145 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 ...
0 votes
2 answers
104 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 ...
0 votes
3 answers
112 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 ...
2 votes
3 answers
256 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 ...
0 votes
1 answer
231 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 ...
5 votes
2 answers
267 views

C programming multiple storage backends

I am starting a side project in C which requires multiple storage backends to be driven by a particular piece of logic. These storage backends would each be linked with the decision of which one to ...
36 votes
7 answers
13k 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 {...
0 votes
1 answer
138 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, ...
1 vote
2 answers
393 views

Inverse of Extract Interface refactoring

I'm working with a Java project that has several interfaces, many of which have only one implementation. (See related question) For a given revision of the software, one could think this acceptable ...
96 votes
8 answers
62k views

Should interface names begin with an "I" prefix?

I have been reading "Clean Code" by Robert Martin to hopefully, become a better programmer. While none of it so far has been really ground breaking it has made me think differently about the way I ...
2 votes
5 answers
518 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 ...
2 votes
4 answers
466 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 ...
-1 votes
1 answer
79 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 ...
5 votes
1 answer
729 views

What is the origin of "Program to an interface, not an implementation"? [closed]

What is the origin of "Program to an interface, not an implementation"? Does it originate from Design Patterns, 1994, by GoF, or from a computer scientist or from some concepts in computer ...
1 vote
3 answers
137 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. ...
0 votes
2 answers
269 views

Where should I start using Interface only?

The more that I'm reading, the less I know about this one. I'm actually working on a new website using Symfony. In Symfony, you have the concept of Entity. An entity represent basically an object and ...
3 votes
2 answers
866 views

Does implementing more interfaces on a class decrease performance?

I had a question regarding the performance of having a class implement multiple interfaces. Is there any degradation in having a class implement 2 interfaces vs 10 interfaces? Background This ...
-2 votes
3 answers
97 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 ...
0 votes
4 answers
146 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 ...
2 votes
2 answers
183 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 ...
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 = ...
0 votes
1 answer
319 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 ...
2 votes
3 answers
156 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 ...
1 vote
1 answer
119 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 { ...
11 votes
5 answers
11k views

Should every class I write adhere to an interface?

I'm writing a game in Typescript, and decided going in that I was going to try to adhere to the idea of "interface based programming", where you write code based on an interface, instead of the ...
2 votes
1 answer
405 views

Should I use RFC 2119 in interface documentation?

RFC 2119 defines several terms, including MUST, SHOULD, and MAY, for use in standards documents, particularly those relating to networking protocols such as IP and HTTP. These terms are widely used ...
1 vote
0 answers
39 views

Looking for the right design (pattern?) for my webapp and external APIs intgerations

I'm working on a simple CRM (Customer Relationship Management) webapp (Flask and Peewee ORM) and I found myself in a situation where I believe that I should have used a design pattern that I may not ...
1 vote
1 answer
114 views

Any workarounds to split functionality from the class?

Hello everyone)) I am working on the react application, where mobx is being used for the state management. Some time ago I have added such class: class EventLogStore { private _eventLogRecord: ...
0 votes
0 answers
48 views

Designing a proof mechanism

DataModel contains a Proof that contains all the information of its integrity along with the method with which the Proof should be verified. In this case I designed a JWS type of proof that can be ...
0 votes
2 answers
121 views

Method that is aware of interface underlying type without reflection

I'm struggling with the design of a method CallSystemX() that needs to accept a parameter of multiple Types. To get around it I created an interface called IRequest to be able to pass different types ...
5 votes
2 answers
3k views

How to create contracts in python

I am currently learning Python (from Java) and have a question on contracts. Example: an application defines an interface that all plugins must implement and then the main application can call it. ...
0 votes
2 answers
142 views

Abstraction way in a bank software system

I am creating a bank software system. In this system, there are 3 account types: Savings, Checking, CD. Each account from any type has an ID, apr, and amount, and we can withdraw from it. So I can ...
13 votes
4 answers
2k views

How do existential types differ from interfaces?

Given the existential type T = ∃X.{op₁:X, op₂:X→boolean} and this generic Java interface: interface T<X> { X op₁(); boolean op₂(X something); } What are the fundamental differences ...
46 votes
5 answers
9k views

What did Rich Hickey mean when he said, "All that specificity [of interfaces/classes/types] kills your reuse!"

In Rich Hickey's thought-provoking goto conference keynote "The Value of Values" at 29 minutes he's talking about the overhead of a language like Java and makes a statement like, "All those interfaces ...
2 votes
2 answers
132 views

How to structure classes for two distinct use cases that share key parameters

I have a Java application that needs to generate mathematically-defined 3D shapes for a voxel world (Minecraft specifically, but that's not important to the discussion). These include sphere, ovoid, ...
3 votes
5 answers
996 views

How to avoid the continuous downcasting in this case?

I have an abstract class Dog and multiple subclasses (Beagle, Labrador, Bulldog...) extendig it. I have a DogHouse that can store a Dog. My problem is that when I put for example a Beagle into a ...
13 votes
3 answers
6k 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,...
0 votes
0 answers
86 views

c# class structuring and appropriate coding techniques

I have 2 classes that share some properties public class SportsUser { public string errorCode { get; set; } //the sportsuser and SportsAdminUser is from a different database hence the long and ...
29 votes
2 answers
5k views

Implementation of pure abstract classes and interfaces

Although this isn't mandatory in the C++ standard, it seems the way GCC for example, implements parent classes, including pure abstract ones, is by including a pointer to the v-table for that abstract ...
27 votes
3 answers
24k views

Generics vs common interface?

I don't remember when I wrote generic class last time. Every time I think I need it after some thinking I make a conclusion I don't. The second answer to this question made me to ask for ...

1
2 3 4 5
14