Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
0
votes
3answers
2k views

Strategy Pattern with abstract class instead of interface?

Is the strategy in the strategy pattern always an interface? What pattern would it be when the strategy is abstract?
1
vote
2answers
112 views

Implementing a Legacy Interface's Method but with different signature requirements

Let's say I have an interface such as Public Interface CarManager { Car getCar(String model); } And I have a lot of legacy classes that implement this interface. But now I have a new ...
-3
votes
1answer
120 views

How can interface work, if there is no code inside its abstract methods?

Interface is used to implement more than one class but it doesn't have any code inside its methods... however the method that is called works with its respective function. Also, it gets very confusing ...
2
votes
1answer
183 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 ...
2
votes
1answer
1k 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
1answer
1k 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
1answer
569 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 ...
1
vote
1answer
629 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
0answers
92 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
0answers
90 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
1answer
618 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
3answers
294 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 ...
-7
votes
2answers
305 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
1answer
132 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
3answers
584 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 ...
14
votes
5answers
713 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 ...
8
votes
1answer
1k 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 ...
7
votes
6answers
982 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
1answer
399 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. ...
4
votes
2answers
2k 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
2answers
1k 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 ...
90
votes
12answers
18k 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
5answers
256 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
1answer
1k 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
1answer
106 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
1answer
327 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 ...
166
votes
9answers
27k 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 ...
2
votes
0answers
58 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
4answers
282 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
3answers
1k 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 ?...
5
votes
2answers
2k 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
3answers
1k 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
1answer
213 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
0answers
105 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
2answers
189 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
3answers
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
2answers
199 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-...
1
vote
0answers
4k 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 ...
3
votes
3answers
459 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'...
4
votes
1answer
3k 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
2answers
152 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
3answers
191 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
1answer
449 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 ...
2
votes
0answers
120 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
2answers
100 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
1answer
135 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
1answer
182 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
1answer
134 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 as follows:...
14
votes
2answers
1k 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
1answer
263 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 ...