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
1answer
273 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
2answers
146 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 ...
26
votes
3answers
22k 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 ...
107
votes
5answers
89k views

Why were default and static methods added to interfaces in Java 8 when we already had abstract classes?

In Java 8, interfaces can contain implemented methods, static methods, and the so-called "default" methods (which the implementing classes do not need to override). In my (probably naive) view, there ...
1
vote
3answers
356 views

Implementing an ILogger: how to make public some fields that are needed in specific implementation of Logger but not in others

I am implementing a custom ILogger (interface for logging). I have succesfully developed implementations of it with some famous loggers like Serilog or Log4Net. Now I want to create a memory logger ...
1
vote
0answers
93 views

How can I improve this API solution

Intro I'm creating an app and I'm not sure if the structure of the solution is correct. I have a BaseController that uses generics. This controller is inherited by others that do not have to ...
-2
votes
2answers
78 views

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

def create() -> sock.sock: ... return sock def create_(func: callable)-> None: ... func(sock) return What are the names of those two interfaces between* a socket creator ...
-1
votes
2answers
101 views

What design/component principle did I apply? How can I further improve it?

I recently refactored a program for code feasibility and maintainability; however, I am totally unaware of what software principle I did implement. I just followed my feeling. The purpose for this ...
3
votes
2answers
124 views

How to handle additional parameter to existing interface

In my existing code, I have an interface like so: public interface IStudentService { T GetStudent(int userId); } This interface is called in many places, and the concrete implementation, let's ...
-1
votes
1answer
34 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 ...
0
votes
1answer
84 views

How can I have two interfaces implement one interface?

I have device interface classes written in c# for electronic variable loads. They are mostly for DC devices. We got a new one that does loading for both AC and DC devices. I also have an interface ...
1
vote
2answers
261 views

Documentation of interfaces

I know how to document a function: /** * Prints a greet message to the web page */ function greet() { echo "Hi!"; } Or describe the usage of a variable: /** * @type string $name The user's ...
5
votes
1answer
374 views

Why were default methods introduced to Java?

Was introducing default methods to java inevitable? As far as I know multiple class inheritance was not introduced to avoid difficulties with the method signature clash in base classes. So we avoided ...
3
votes
1answer
182 views

Method call order dependency

I have two camera devices that are able to find a specific hardware illuminated point in an image, as well as measuring the physical distance to the surface (and some more stuff I chose to leave out, ...
1
vote
1answer
133 views

C#: Should I define methods as async?

I have a C# (WPF) application which consumes a particular 3rd party API/tool (let's call this Tool A). My colleagues and I are trying to decouple that from our application, so that it is possible to ...
1
vote
2answers
122 views

Is there a difference between abstract data type and interface?

From what I understand, an abstract data type is basically some data and what we are allowed to do with that data (ex. a list with a set of data and an attribute size and the functions get(), set(), ...
-3
votes
1answer
78 views

What is meant by service? [closed]

We know there are services in windows but I am reading a book by Ed Snider and he uses the term “service” whenever his program requires a certain feature/functionality. Like he creates a navigation ...
0
votes
4answers
149 views

When to pass a concrete object, vs a way to obtain the object

Say there is some view that displays user details like name, age, email, etc. That view could maybe be constructed with the following pseudocode: UserView(User user); And that view would be able to ...
2
votes
2answers
232 views

Would de-coupling using interfaces/templates make the system easier to maintain at the cost of over-engineering?

I have been practicing this hybrid approach for dependency injection in the last couple of days and I am wondering if it should also apply to components which are within the same package? For example:...
0
votes
4answers
198 views

Is it an issue to have multiple almost identical interfaces?

Is it an issue to have multiple almost identical interfaces? In our company we have 9 identical interfaces for 9 document types, like: Book, Contract, Person, etc. interface IBookInner { Book ...
1
vote
2answers
95 views

In C#, is it reasonable to use a #region when I need several members to implement a common interface?

I know that lots of people hate #regions in C#. IMO there is at least one legitimate use of them: Sometimes I have a class which, in addition to its core functionality, needs to implement a commonly ...
0
votes
3answers
69 views

Logically grouped interfaces have circular dependencies in call graph, tight coupling. Leave as is, break up CRUD interfaces, something else?

The problem I have relates to an existing system in a specific business domain. I've simplified it into a very similar 'Library/Book' relationship to articulate the problem. Answers such as 'why would ...
3
votes
2answers
128 views

Composing and Inheriting from the Same Type

To start off with an example: I have a read-only Repository used for getting arbitrary values. This behavior can be implemented multiple ways. I also want to allow opt-in mutation of the repository's ...
1
vote
2answers
2k 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 ...
3
votes
3answers
158 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 ...
18
votes
8answers
5k views

Is it ok to inherit a class without adding anything to the child, to respect the Open Closed principle?

To clarify the question, here is my context (or something very similar). I have an interface, that I call IDataSource. The implementing classes contain information to retrieve data. So I have multiple ...
-4
votes
2answers
94 views

IO stream interface in C

When writing a library (eg. for dealing with JPEG or PNG files), the first thing library author needs to provide is an abstraction over FILE* (to allow also reading from plain memory, pipe, socket, ...
3
votes
1answer
138 views

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

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 ...
1
vote
2answers
871 views

Depend on DDD Entities or Interfaces?

My understanding is that the dependency inversion principle does not apply to entities, because entities basically are your application - it generally doesn't make sense to swap out a different ...
0
votes
4answers
349 views

Why have separate keywords for 'extends' and 'implements' in Java? [closed]

Short answer that I've come to accept: Firstly, it helps with readability, being able to see which is the superclass apart from interfaces. Secondly, though 'extends' and 'implements' do the same ...
8
votes
4answers
3k views

OOP Design considering no modifications to existing design

The question is: interface Animal { void eat(); } class Lion implements Animal{ public void eat(){ //do somethng } } class Test { public static void main(String[] args) { ...
8
votes
2answers
6k views

Why generic interface cannot implement dynamic type?

If it possible IList <dynamic> = new List <dynamic>; or class A <T> { } class B: A <dynamic> { } Why it is not possible to do class U: IEnumerable <dynamic> {} ?
0
votes
0answers
17 views

Including widgets of a specialized program inside another program

Let's say my goal was to write a graphical application (based on a game engine, or even raw OpenGL), which should be able to render arbitrary 3D graphics. Now let's say I want to annotate the ...
16
votes
5answers
3k views

Use of keyword “Using” in C# interface

When I'm using C# to write some code and I define an interface using Visual Studio 2010, it always includes a number of "using" statements (as shown in the example) using System; using System....
7
votes
3answers
577 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
57 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
498 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
188 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
129 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
110 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
114 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
59 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
161 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
225 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 ...
0
votes
1answer
3k views

Interfaces between multiple projects

I'm slightly confused over the following: ProjectA -------- GetUsers (Implements IDBConnector) -------- IGetUsers -------- UserModel ProjectB -------- Main I have two projects one main project (...
-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) ...
8
votes
1answer
31k 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
143 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
2 3 4 5
14