Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [interfaces]

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

1
vote
0answers
65 views

Does it make sense to implement a Class Factory design in an RPG Character Creation module

I'm a self-taught Engineer, a beginner in Java and I am trying to create a Dungeons and Dragons character creation module for a bigger game to solidify my understanding of core concepts while learning ...
1
vote
1answer
89 views

Handling multiple game modes with a game controller

I have a basic GameController with a finite state machine to handle game logic. I'm adding game modes and coming across problems cleanly implementing them. The core functionality of the game stays ...
0
votes
1answer
46 views

How to structure a set of classes that deal with external APIs for maximum testability?

I'm developing a set of classes designed to communicate with external APIs, and I'm running into trouble with how to properly structure everything for proper loose coupling and unit testing. ...
1
vote
2answers
67 views

In some IOC contexts, could constructor of polymorphic immutable object be required in its interface?

Generally, constructors in an interface are considered as being an anti-pattern. Some languages even don't allow that. Then I don't understand how we're supposed to deal with polymorphic immutable ...
1
vote
1answer
114 views

Is it a good design to create an interface that inherits from multiple interfaces to reduce the amount of dependencies of a client?

I was refactoring an application to respect SOLID principles. When I was applying interface segregation I found the following case: interface A { void methodA(); void methodA2(); } ...
1
vote
1answer
69 views

Using generics on interfaces when implementation is not generic

Is it acceptable practice to put generics on an interface when the implementation will not be generic? Lets say that my project will have many classes that read data from the database. I may make a ...
1
vote
5answers
305 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 ...
0
votes
2answers
108 views

How can I force an object that respects an interface to output a certain data type / structure with its functions?

This is exactly my code, I'm just stripping out everything that isn't needed: First of all, I met this issue a lot of times and something tells me that it's something to do with PHP itself and "data ...
0
votes
0answers
17 views

controlling multiple components in web application

In my small web application (about 3k lines) my UI is composed of lots of buttons, toolbars, selection boxes, tables etc. Where each action affects the state of multiple UI elements. Do you ...
1
vote
1answer
145 views

Can (Java) Interfaces be referred to as APIs? [duplicate]

I am trying to understand what exactly an API is. From my current understanding, an API (Application Programming Interface) is a contract provided by a software instance, that guarantees a defined ...
-2
votes
2answers
53 views

Interface name for time-based classes

I'd like to document that code encapsulated in a class is "time-based" in a Java-like language – the code behaves differently based on what time it is currently. To make it testable, it would read ...
7
votes
5answers
331 views

Information Hiding v.s. Static Type Safety

I'm working on a project with others and we have a discussion about information hiding and static type safety. Our scenario is described below. Language: C++11 Scenario: We want to create a tree-...
2
votes
1answer
56 views

What to choose, ioctl-like interface or a set of distinct methods?

I am implementing a messaging protocol between nodes on a network and i am wondering how to expose the messaging system interface to the programmers. The messaging protocol supports a set of commands ...
1
vote
1answer
94 views

What would be the downsides of creating a derived interface of interface?

Would there be any downsides of creating sub-interfaces for virtual member functions that have different parameter types? A drawing of this is shown in the image attached. Apple and Orange do not ...
1
vote
1answer
113 views

Can a class represent two implementations?

I'm unsure about several things: I have a class that implements a NotificationDispatcher interface. This class I named WhatsappNotificationDispatcher, another implementation goes by ...
1
vote
1answer
166 views

to ISP or not to ISP?

I've got a design problem, and I figure it's not something totally uncommon so there must be some good practices out there. I have 2 domain entities: Process and Task. A Process is essentially a list ...
4
votes
1answer
95 views

Repository that performs API calls internally - DDD

Please note: although my question relates to DDD, I am also interested in this from an architectural and OO design perspective. This question may also be a simple case of CQRS and/or interface ...
0
votes
2answers
122 views

How to handle state of an object? And how to enrich the state transition logic?

I am designing a class that has a state. I wonder if I should expose that state in the interface in view of allowing a decorator to enrich the state transition logic. Shall my design expose ...
1
vote
1answer
85 views

An interface for designing Arduino code

Often I want Arduino board to control several peripherals. Writing program for all of them in one document using #define SOME_PIN 4 constructions seems pretty inconvenient to me. Especially in such a ...
2
votes
3answers
506 views

What is the name of this pattern (if any)?

There's a sort of pattern that I've sort of stumbled myself into "discovering" that seems extremely useful, but I've never seen it described before. It's sort of a way of achieving inheritance through ...
0
votes
2answers
167 views

Complex interfaces in multilayer project

In my C# project I need to swap data providers in the future so I have created interfaces to build future providers off of. But this is the first time I have worked with interfaces that are "complex" ...
1
vote
1answer
80 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 ...
4
votes
3answers
229 views

Decoupled design using static interfaces

Now first I want to mention that I am not quite sure what is the term describing the issue at hand but I hope that I can illustrate it with some code. Problem: A shared class library defines an ...
0
votes
1answer
53 views

What to specify as interfaces in component diagrams

I am following the textbook Object oriented software specification using UML, patterns and Java (3rd edition) and I am defining interfaces between system components (subsystems). But I encountered a ...
2
votes
1answer
52 views

Abstraction for Account transactions and balance

We have 10 applications which updates account balance table, without logging credit/debit line transactions (not sure why). They all have the pretty much same SQL Statement. In order to get out of ...
0
votes
1answer
65 views

Would you implement an interface to connect to a database?

I found in a book (Learning PHP Design Patterns, Chapter 2, page 25) a text explaining the importance of interfaces in OOP design. The author ended up by giving this example: <?php interface ...
0
votes
0answers
25 views

Implementing the Repository-Client and Interface Pattern with a common controller assembly

I'm currently working on an MVC project for a web utility. This utility takes input from a user, sends it off via JSON to an API that reads from a database, and brings the data back in tables; it does ...
4
votes
5answers
522 views

Newbie question: 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, ...
4
votes
4answers
188 views

Should custom exceptions live with the interface or the implementation?

I have an interface IMyService in a class library. I have an implementation of this interface MyService in a separate class library. MyService may raise a custom exception CustomException. Should ...
0
votes
4answers
584 views

Avoiding vtable pointers in objects in C++

In my previous question, it was highlight that implementations of C++ such as GCC must store a vtable pointer in every copy of a class for each parent class which has a virtual function. So a class ...
0
votes
3answers
134 views

Implementing interface using class members

This was just a question I was wondering about in terms of best practice. I am writing a small C++ program that uses an interface to implement a function. In the class that uses the interface (i.e. ...
12
votes
5answers
4k views

Does it make sense to define an interface if I already have an abstract class?

I have a class with some default/shared functionality. I use abstract class for it: public interface ITypeNameMapper { string Map(TypeDefinition typeDefinition); } public abstract class ...
0
votes
2answers
126 views

Use case for interface

While going through some lecture video on interface. I noticed If we don't know about implementation, just requirement specification then go for interface. What can be the scenario? Though I've ...
2
votes
1answer
97 views

Whether to replace mutually exclusive but poorly related properties with an interface

A few years ago I designed a class which had two properties. The two classes ChildA and ChildB had a rich protocol with many properties and methods, but were only distantly related in my model. They ...
0
votes
3answers
534 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 ...
25
votes
2answers
3k 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 ...
-1
votes
1answer
129 views

Does Interface Segregation Principle apply to parameters/request objects?

I have recently seen an example of what I think is a clear violation of ISP, but my colleague argued it is easier to use. This is what happened: We had Options class that had 2 fields sent as a ...
0
votes
0answers
37 views

ASP.NET RoleProvider AddUsersToRoles - Removing exception if user already has role

I'm implementing a custom RoleProvider in my ASP.NET web app, however I had a question about the example implementations of AddUsersToRoles and it's Remove counterpart shown here: https://msdn....
1
vote
6answers
454 views

How can I unit-test the presence of specific file contents, through an interface?

I am currently trying to test a file manager class. This class is responsible for keeping track of how long the file is good for. The file will have a date written into it that denotes when it was ...
2
votes
5answers
372 views

Interfaces Everywhere? - Best Practices [duplicate]

There is a discussion at work about the correct use of interfaces in OOP. I have been taught, and always worked from the premise, that interfaces precede concretions and all methods should be dealing ...
1
vote
2answers
111 views

Interfaces for CRUD Classes

In an in-house solution I've been working on, I've been unable to understand the benefit of how interfaces are frequently implemented throughout the project. Which is as follows: Want to do CRUD ...
1
vote
2answers
180 views

Implementing interfaces vs using a base class

I am writing an application in python. The part I am little confused about is providing a little structure to my code. This is the basic requirement of my web application. I have these different ...
-3
votes
3answers
66 views

Naming: How do you call an interface that allows to retrieve items?

Let's say a client need to get a list of products from somewhere. He does not care if that list comes from a cache, from a remote database, from a local database, from the resources or from the remote ...
1
vote
1answer
75 views

Interfaces for waypoints

I have a waypoint class which i use to connect a bunch of other waypoints up. But i also have a special type called a consumer, this is not technically a waypoint but it needs to act like one in that ...
0
votes
2answers
150 views

Use getter interfaces as a way to reuse DTO fields

Assume I have a lot of DTO for a same domain model like this: class User{} //DTO @Value.Immutable interface SimpleUserDTO { getName getAge } @Value.Immutable interface RegisterUserDTO ...
2
votes
1answer
64 views

Should I create seperate interfaces as a way to centralize annotation?

Assume I have these classes: @Entity @Data class Student{ @Size(min = 8) public String name; public int age; ... } @Data class StudentDTO{ @Size(min = 8) public String name; ...
0
votes
1answer
74 views

Avoiding concrete references, should expressing relationships be an exception to the rule?

I have a critical business object GroupMembership that represents the relationship between an user and a group. I have set an architectural policy that critical business objects should avoid ...
1
vote
1answer
539 views

Difference between header files and interfaces

I wanted to know whether the header files in c and c++ have same function as that of interfaces used in Java? If not what is the difference between header file and interface?
1
vote
3answers
201 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, ...
7
votes
1answer
236 views

Should every method in a class be defined in an implemented interface?

I can see how interfaces are very useful to force different classes to have the same functionality. But there are also actions that are bound to a specific class (like updating an unique variable ...