Questions tagged [interfaces]
Questions about `interface` related design considerations, and also "programming to the interface instead of the implementation"
725
questions
2
votes
1
answer
816
views
Major or Minor Revision Change when Implementing an Interface
I am using semantic versioning 2.0.0. In my situation I have a concrete implementation of some interface A in one library. And I have the interface that's being implemented (call it B) in another ...
3
votes
1
answer
2k
views
Is it bad practice to perform an "optional" interface inheritance?
Say... you're trying to write a networkCallback code in java:
public interface NetworkCallback {
void onNetworkResult1(Object object);
void onNetworkFailure(Object object);
}
you want to use ...
-3
votes
1
answer
2k
views
How to decouple a dependency
I am trying to decouple a dependency from Book Class to BookStorage, but got confused how to do this right. Can someone tell me how to decouple this correctly? Here is my code:
public interface ...
1
vote
1
answer
763
views
How to figure out what interface to cast to?
This question may be a bit subjective, but I have tried three different solutions and none of them has felt right. I will provide some context and the solutions I have tried. The issue I am facing ...
2
votes
1
answer
1k
views
If polymorphism is the ability of different types to share the same interface, is there a name for a single type that fulfills different interfaces?
Consider this example of polymorphism. I have two different API, IWrite and IRead, and then a single implementation of these.
interface IRead
{
Entity Find(int id);
}
interface IWrite
{
void ...
1
vote
0
answers
103
views
Receiving events through an interface
So I'm writing a game and using the Google Play Services framework to send and receive data.
I have to implement the IRealTimeEventListener interface and override the functions below to receive ...
1
vote
0
answers
106
views
Should every class in my system have an interface? [duplicate]
Should every single class in my system have an interface?
I understand that interfaces provide an abstraction from the implementation of a class and so changes to the implementation do not affect ...
1
vote
1
answer
1k
views
Is it correct to think of a Java Interface as a "contract" that a class must implement?
I just want to check that my current understanding of Java interfaces is correct.
If an interface says it must include public void increase(int amount), then does that just mean the class that ...
4
votes
3
answers
379
views
Is an interface with two collection properties, where the second filters the first collection, idiomatic for C#?
I had an interesting discussion with a coworker that revolved around how people interpret the use of properties and methods on an interface. For example, let's say we have a blog with posts in various ...
-6
votes
2
answers
454
views
Why are interfaces in Java called that way?
I have been a developer for past 3 years and I have been seeing interface in most of the places as a contract for the developers to write their own implementation or a marker (eg. Serializable). But ...
1
vote
1
answer
153
views
Refactoring List abstraction - C
Below is the working List abstraction design,
List is a generic abstraction holding any type.
Below is the code directory structure. Currently symbol table(ST) and file api fileIO is using List ...
3
votes
3
answers
1k
views
How to remove dependencies on internal classes in the interface
I have a software component that is a part of a bigger software product.
The software component lives in its namespace Component.
Also the component has an interface (some part of it is below) that ...
15
votes
5
answers
1k
views
How to apply the Interface Segregation principle in C?
I have a module, say 'M', which has a few clients, say 'C1', 'C2', 'C3'.
I want to apportion the module M's namespace, i.e. the declarations of the APIs and data it exposes,
into header file(s) in ...
9
votes
1
answer
2k
views
In a multi tier project where should interfaces be defined?
I have a multi tiered project made up of three sub projects, i.e. Data access project, Business Logic project and Presentation project, where should interfaces be defined?
I'm guessing that there ...
9
votes
6
answers
4k
views
How do large engineering teams describe the interface/contract between a web service and client JavaScript code? [closed]
I'm looking for a formal way for a front-end and a back-end team to communicate on the shape of a JSON web API. For example, let's say you are on a client-side team writing the JavaScript & HTML ...
3
votes
1
answer
534
views
Contract interface/class with inner classes/interfaces
Brief description of my project structure.
I have some base classes like BaseView, BasePresenter ... .
Also my project consists of modules, module represents one complete part of the application.
...
5
votes
2
answers
4k
views
Library IO: Use Interface classes or Callbacks?
I'm building a smallish library (few kLOC) which processes stream data in C++. From the streamed data (comes in packets) the library compiles a database piece by piece and naturally has to convey that ...
5
votes
2
answers
3k
views
Interface extension method returning the interface type in C#
Programming against interfaces is an often-heard good practice in software development. Together with extension methods, this provides a great functionality. However, in C#, there are limitations to ...
96
votes
12
answers
20k
views
What is meant by the phrase “Software can replace hardware”?
Studying beginners course on hardware/software interface and operating systems, often come up the topic of if it would be better to replace some hardware parts with software and vice-versa. I can't ...
6
votes
5
answers
1k
views
Is there something wrong with having one interface to be implemented multiple times in inheritance chain?
interface IUser {}
interface IConcreteUser : IUser {}
abstract class UserBase : IUser {}
class ConcreteUser : UserBase, IConcreteUser {}
As you can see, ConcreteUser inherits IUser two times - one ...
4
votes
1
answer
2k
views
Is Design by Contract the same as using Interfaces to create a "contract"?
Does an OOP design that uses a Design by Contract mean the designer is using interfaces to create a "contract." The term "contract" is used quite often when discussing OOP interfaces, so I didn't ...
4
votes
1
answer
122
views
Message publishing interface when deferring until transaction is committed
Suppose I have the following interface used for publishing messages onto a message queue:
interface IMessageProducer
{
void Publish<TMessage>(TMessage message);
}
Normally, an implementer ...
3
votes
1
answer
871
views
When adding a property to an interface in C#, is that consider major, minor, or patch using semantic versioning?
My team and I are trying to follow semantic versioning 2.0.0 to keep tabs on our library versions. We primarily use C# for our development and are currently in a situation where we are going to add a ...
169
votes
9
answers
29k
views
I changed one method signature and now have over 25,000 errors. What now?
I started a new job recently where I am working on a very large application (15M loc). In my previous job we had a similarly large application but (for better or for worse) we used OSGi, which meant ...
3
votes
0
answers
72
views
Entity Framework - Old school save/update advice?
I've a query for you relating to best use of EF6 when using Winforms yet not having justification for changing things to something more modern.
I've got half a dozen classes that are based on ...
6
votes
4
answers
813
views
Evolving an interface that is not supposed to be implemented by the client
I'm about to write a Java library. Basically, this library provides something like this to its user:
interface Foo {
void doA();
boolean aWorked();
void doB(int value);
}
The user is not ...
9
votes
3
answers
2k
views
Is it OK for interfaces to depend on concrete classes?
I am creating interface in Java for custom error handler.
Want to pass an argument error object but I need it to be child of Exception class.
Is it okay to use my defined class name in an interface ?...
6
votes
2
answers
3k
views
Is it ok to have an empty abstract class to make concrete classes polymorphic
BEFORE:
I have an interface that has one method definition
public interface IDockable
{
void Dock(DockerContainerConfig config);
}
Everything is ok for my first implementation
public class ...
2
votes
3
answers
2k
views
What does the following definition of an interface mean?
I am reading Real-Time UML Workshop for Embedded Systems and I do not understand what they are saying here. I have bolded the parts of the text that I do not fully understand. I am trying to ...
3
votes
1
answer
249
views
Is Pairing a bloated interface with an Enum a good idea?
At work we have an interface that is getting bloated. The interface is designed to be easily implemented by an immutable object. So it looks something like this:
//there is no behavior here, just ...
1
vote
0
answers
131
views
Sending events down a tunnel, and bubbling them back up
I am working on developing an HTML canvas application, where I need to be able to do my own UI event processing. That's where the stem of this question comes from, but I'd really like to understand ...
2
votes
2
answers
271
views
General approach to an interface that will resolve a dependency to a database library
Background
I often write software for systems that are responsible for testing manufactured products. For every product that gets tested, we have to generate a report for the test-results. The way ...
13
votes
3
answers
3k
views
Is this bad OOP design for a simulation involving interfaces?
I am designing my own little OOP program to simulate Vampires, Wolves, Humans and Trucks and am trying to implement my own limited understanding of Interfaces.
(I am still abstracting here and have ...
5
votes
2
answers
213
views
How to bring others to understand your interface
I'm working in a corporation that has two products. One is a desktop application the other is a web-application. I'm in on the part as backend-engineer on the web-application. I design the web-...
2
votes
0
answers
8k
views
ASP.NET: Creating an interface for a controller
Would creating a controller's interface a bad idea? I have a controller that derived from ApiController, so knowing that you can only derived one class to a class but able to derived one or more ...
2
votes
3
answers
990
views
How to decide, should I put methods to abstract class or to interface?
I'm writing an app it needs to have generic registration step item. It needs to be able to do some specific things (I use interface for that) and it needs to be a visual element (of Xamarin. It doesn'...
5
votes
1
answer
6k
views
Interface with multiple default methods OR Interface + Class
In a code base I am "starting from" there are a handful of interfaces with many default methods. They look something like this:
public interface HasXY {
double getX();
double getY();
...
3
votes
2
answers
169
views
Function acting as a shortcut to object's methods
I was reading Python's requests library's code to find out how it works. Since this library has a simple usage interface, it creates a more complex object beyond. For instance:
requests.get(...)
Is ...
3
votes
3
answers
206
views
Is it good practice to create interfaces that limit usage?
So I'm coding a way to send events to multiple clients, and then having the clients decide how they want to handle it. I'll exclude the bits that don't lend themselves to explaining the situation.
...
5
votes
1
answer
2k
views
How to properly extend an interface with immutable properties to offer mutability via another interface
The following code snippets are simplified to demonstrate the context!
The actual interfaces and classes are POCOs having additional properties. The types are part of library I am working on, the ...
3
votes
0
answers
132
views
Interface Methods vs Data Objects
Building a UI editor for Android and basically there are interfaces such as this:
interface Item {
fun decorate()
fun translate(x: Int, y: Int)
fun rotate(rotation: Float)
fun scale(...
2
votes
2
answers
661
views
Modifying an existing class: should I extend it to a new class?
I'm working with a library (from an online source, not authored in-house) providing an interface as well as an implementation of it:
interface FooInterface {
// ...
}
class Foo implements ...
1
vote
1
answer
819
views
Force implementation of an interface to use a function, to enable functionality that's transparent to the user
I am the designer of an interface IModel, which will be used by the implementer of a the controller (MVC). The interface contains funcA().
Another programmer needs to implement a specific class for ...
1
vote
1
answer
413
views
Having the implementer as a property in an interface - is it bad practice?
I have an interface IFoo that only gets implemented by objects with a fairly high level (framework) base class. It would be very useful to me to not only get the Interface members, but also the ...
3
votes
1
answer
178
views
Leo Brodie's "Interface Component"
On page 85 of Leo Brodie's book, Thinking Forth, he describes a component which he calls the "Interface Component." He describes its differences from, and benefits over a standard interface ...
15
votes
2
answers
3k
views
Now that not all method declarations in a Java Interface are public abstract, should the methods be declared with these modifiers?
Starting with Java 8, default methods were introduced into interfaces. Effectively, this means that not all methods in an interface are abstract.
Starting with Java 9 (maybe), private methods will be ...
2
votes
1
answer
553
views
Is this a good way to keep track of subscription cycles and figure out if we need to charge the subscriber?
I'm working in PHP and building a subscription management system from scratch.
I'm trying to figure out the required functions for the Subscription interface (OOP) that need to be implemented by ...
2
votes
1
answer
1k
views
What are mIa, mId and dIa interfaces?
This document on European Telecommunications Standards Institute website describes some Machine2Machine (M2M) communications protocols. I've seen mIa, mId and dIa interfaces in some research papers, ...
7
votes
2
answers
392
views
Java redeclare inherited interfaces?
While working on a small class called FractionNumber I found asking myself if I should implement an interface that I am already implementing. Sounds stupid, I know, but bear with me.
My class ...
3
votes
2
answers
240
views
Defining reusable components while having a specific application in mind
Over the past several months I have learned a lot in software design and practices across several languages and frameworks. To me, the most attractive and useful designs patterns are those that follow ...