The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
271 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
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 ...
5
votes
1answer
5k views

Structuring projects in a solution for interfaces

I had this idea that I would achieve some good automation and separation of concerns as follows: Define an interface, IDataProvider, in a class in a DataMuncher project that needs to both consume and ...
-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
575 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
649 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 ...
4
votes
3answers
299 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 ...
1
vote
1answer
665 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 ...
15
votes
5answers
14k views

Can I consider interface methods as abstract methods?

I was thinking about that, and I had some doubts. When I declare an interface, for example: public interface MyInterface { public void method1(); public void method2(); } Could these ...
15
votes
5answers
732 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 ...
-7
votes
2answers
306 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
133 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
618 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 ...
11
votes
3answers
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 ...
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 ...
3
votes
1answer
413 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
1answer
482 views

The inheritance argument of zope.interface (providedby vs isinstance)

What limitations does inheritance of an interface through an abstract base class present that are addressed by zope.interface? In the following talk given in 2010 by Jeff Rush about interfaces, at 11:...
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 ...
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 ...
7
votes
4answers
4k views

How to force “program to an interface” without using a java Interface in java 1.6

In java 1.8 they have wonderful new "default interface methods". In 1.6 how close can we come? The goal: use code to keep clients from being able to tell that a class is not a java interface. If we ...
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 ?...
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
108 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
342 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 ...
1
vote
3answers
487 views

Is interface containing every method of given class a good thing?

I'm trying to write a simple game and I really want to finally create something that would be "programmatically correct". I stuck with a problem like this: I have class public abstract class ...
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 ...
6
votes
4answers
283 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 ...
29
votes
11answers
11k views

Declaring interface in the same file as the base class, is it a good practice?

To be interchangable and testable, normally services with logic needs to have interface, e.g. public class FooService: IFooService { ... } Design-wise, I agree with this, but one of the things that ...
3
votes
0answers
60 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 ...
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 ...
1
vote
2answers
669 views

Define Interface Simplicity vs Implementation Simplicity

In Richard Gabriel's The Rise of "Worse is Better", he talks about the simplicity of interface vs the simplicity of implementation in a design. I've never been able to quite grasp what he means and ...
1
vote
0answers
107 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
206 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 ...
29
votes
10answers
19k views

Interfaces on an abstract class

My coworker and I have different opinions on the relationship between base classes and interfaces. I'm of the belief that a class should not implement an interface unless that class can be used when ...
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
200 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-...
7
votes
2answers
5k views

Why generic interface cannot implement dynamic type?

If it possible: IList <dynamic> = new List <dynamic>; or: class A <T> { A(T){} } class B: A <dynamic> {} . Why it is not possible to do this: class U: IEnumerable <...
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
285 views

When and why would you put a new method into an interface instead of an abstract base class?

I have been asked the following question in an interview: "What is the need of an interface when you can have an abstract method within an abstract class?" Which I did not know the answer to. Could ...
7
votes
1answer
200 views

Should an interface covariant on T ever implement an interface invariant on it?

I was reading through the Hacklang docs on Collections, and came across this curious definition [paraphrased slightly]: interface KeyedIterable<Tk, Tv> ... interface ConstVector<+Tv> ...
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
504 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 ...
47
votes
3answers
66k views

Why does C# allow properties in interfaces?

In C#, the following code is valid interface I{ int property{get;set;} } Which doesn't make any sense to me. This seems to break one of the most important principles of interfaces: lack of ...
3
votes
0answers
121 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(...