Stack Exchange Network

Stack Exchange network consists of 175 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.

0
votes
2answers
197 views

Is implementations not being interchangeable and having to cast often a code smell?

I'm building a small game similar to chess. I'd like to be able to reuse the structure for another version of checkers too. I'm modeling the games with interfaces (showing only relevant ones): ...
-1
votes
2answers
130 views

How should i pass a generic filter for database queries?

I have a interface DataStore, which provides access to a generic data store, e.g. a local database, webserver, etc. I want to provide a way to filter results directly in the query. How should i pass ...
0
votes
1answer
127 views

What to do about many small, semantically similiar types?

I'm working on a non-generic server-client-architecture in Java. Currently, I face the issue of how to tackle Event-types since each event has different attributes, which don't overlap neccessarily. ...
0
votes
1answer
85 views

Moving interfaces but not concrete classes

Recently I started working on creating a client library. One problem which I am facing now is that I have to move the below interface Attributes to client library but the concrete classes (business ...
2
votes
2answers
276 views

Does implementing more interfaces on a class decrease performance?

I had a question regarding the performance of having a class implement multiple interfaces. Is there any degradation in having a class implement 2 interfaces vs 10 interfaces? Background This ...
0
votes
2answers
76 views

CLI to Aid Versioning of Input, Source, and Output

I'm currently working in an environment where I have the following: Multiple Inputs (with multiple versions) Source code to generate output (multiple versions) Output generated by a combination of ...
7
votes
2answers
672 views

What should I do with implementation-specific exceptions?

Let's say I have an interface describing a simple service public interface AccountService { public int getUserId(String userName) throws UserNotFoundException; //... } I've written the ...
4
votes
1answer
297 views

Dealing with a large interface

I'm working on a program that solves a certain type of systems of equations. The main data objects are Equation, Variable, Solution. Then I have this interface, which represents all things that I want ...
0
votes
1answer
2k views

Best way to design a class interface passed to library/plugin

I have an application comprising a bootstrapper executable, a core library and several plugins (shared libraries). The core library is implicitely linked to all components, the plugins get linked/...
-1
votes
1answer
296 views

The pythonic way: replacing interfaces with ducktyping vs inheritence

tldr: I have consumer-like classes that require a number of pieces of information to do their job. It's an "all or nothing" kind of thing: the "producers" providing them with data need to provide all ...
12
votes
3answers
18k views

How to best to organize class and interface files?

OK .. after all the discussion I'm changing my question slightly to better reflect a concrete example that I am dealing with. I have two classes ModelOne and ModelTwo, These classes perform ...
5
votes
4answers
3k views

Are empty interfaces (but not marker interfaces) a bad programming practice?

I'm designing an architecture in which I have: public interface IObjectReader{ public Object read(); } public class ConcreteObjectReader implements IObjectReader{ @Override public ...
0
votes
1answer
53 views

Binding an interface on top of third-party modules to develop future-proofed and scalable apps

Every day a couple of new javascript modules are created and published around the world and we need to think long term. Let's say today I need to use an ORM module to go smooth and fast. But tomorrow ...
1
vote
1answer
249 views

Marker interface - what's a practical code example of 'communicating a semantic constraint/guarantee that doesn't otherwise change the API

Let's start with a loose definition of 'marker interface' (please correct me or dispute this if you disagree): If applied to a type, a marker interface doesn't provide any contract of methods to ...
0
votes
1answer
125 views

How to provide Java libraries internally?

In my small team we write applications that run as a Jenkins job and using the SOAP API of our Bug Tracker, our ALM software. They are accessed with Java however I think developers using other ...
3
votes
3answers
179 views

What is the motivation or usage to create a interface use once only just for breaking circular dependency?

I understand if 2 classes have circular dependency, eg: public class MyWindow{ public MyWindow(){ new MyDialog(this); } public onDialogResponse(int option){ } } public class ...
3
votes
2answers
370 views

What is the benefit of using an interface that doesn't enforce anything (marker interface)?

The codebase I'm working on makes a lot of use of interfaces that don't actually enforce anything. They're in place more to make sure that a type 'is a' something. For example: public class ...
-2
votes
2answers
3k views

Separate interface from implementation

What is the meaning of separating interface from implementation in C++? And also what is implied by interface and implementation?
1
vote
2answers
1k views

What pattern for implementing multiple interfaces on the same type?

Description of the environment: I am implementing a (hobbyist) modern engine for (an old) PlayStation 1 video game Graphical data is represented as packets where it can represent either a polygon or ...
0
votes
1answer
716 views

Interface design of Java library with interdependent yet decoupled packages

I plan to write a library in Java, consisting of packages A, B, C and so on. Every package encapsulates a part of the big picture. B relies on A, C on B and so on. For this purpose every package ...
1
vote
2answers
157 views

What is the name of the pattern for having libraries that “provide” functionality based on the interface?

I am wanting to build a generic middleware software for my company that can access various vendors API's to pull out orders and then import then into our ERP through its API. I want to make this as ...
13
votes
1answer
772 views

Java Default Method Usage

For decades it's been the case that interfaces were only only (only) for specifying method signatures. We were told that this was the "right way to do things™". Then Java 8 came out and said: ...
4
votes
3answers
683 views

Clarification on the Dependency Inversion Principle

I'm reading the book "Agile Software Development, Principles, Patterns, and Practices" by Robert C. Martin. When he talks about the Dependency Inversion Principle he gives the following example of a ...
1
vote
2answers
161 views

Extracting data from third party program i.e. craft an unofficial API

If got a native application which adds value by for instance analyzing measurement data from measurement programs. Some of them have an API, so I can get their data via IPC. But how can I achieve this ...
0
votes
1answer
150 views

Discover implementations of interface

Let's say, I have an interface ISomething. I also have up to n implementations of the interface, for example ASomething and BSomething. I want to determine all the implementations of that interface ...
1
vote
2answers
2k views

share method logic along classes without inheriting from abstract class

In some languages (e.g. C#) a class can only ever have 1 base class which seems like a problem for what I'm trying to do. I will give you an example of what i'm trying to do, hopefully this will make ...
1
vote
1answer
66 views

Handling more specialized interface with no code duplication

I have the following code: struct AInterface { XXX some_method(/* some params */) = 0; }; void foo(const AInterface & a) { do_work(); while (x) { do_work_2(); ...
11
votes
5answers
3k views

Using Func instead of interfaces for IoC

Context: I am using C# I designed a class, and in order to isolate it, and make unit testing easier, I am passing in all its dependencies; it does no object instantiation internally. However, instead ...
7
votes
9answers
1k views

Another “Why use Abstract/Interface” question. But I'm a solo developer. Why use it?

I know the purpose of it and everything. I see myself as a solo developer for a couple more years. I always see answers that it is contract. Yes I get it. But here's something on my mind: If a ...
0
votes
2answers
319 views

Add method to interface for only one implementation

I have a factory for an interface with different implementations. But one implementation needs an extra method which the others don't need. How do I solve this without implementing "not implemented ...
1
vote
5answers
586 views

Facade pattern or just expose child objects?

Wondering about pros and cons around a facade pattern implementation (or perhaps there is a better pattern I should consider), versus simply exposing a dependent object to a caller. Consider the ...
0
votes
1answer
150 views

software design for a class utilizing many different services

I am trying to model a design for a C# project. Trying to follow the SOLID principles, this is what I've got so far: SDKClient class which has three (for this explanation) important properties (...
4
votes
2answers
163 views

Is there a methodology for switching large code base to be interfaced-based instead of direct class access?

Our organization codebase is used by various teams. Over the years, the code has evolved and grown without much usage of interfaces. We would like to change that, to reduce chance of breaking changes. ...
3
votes
2answers
193 views

Is it a good practice if using Object when a method can accept more than one type of object?

public class TaskA implements Runnable { .... } public class TaskB implements Runnable { .... } I have two runnable class as TaskA, TaskB. I want to have a TaskManager to run these two tasks and have ...
3
votes
2answers
2k views

Where should I use abstract classes vs interfaces for a REST API client?

I'm trying to write a REST API client for practice and I'm having trouble figuring out how lay out the project. The approach I'm taking right now has Actions, DomainObjects, Requests, and a class ...
-2
votes
3answers
506 views

Can I say Interface is a set of general behavior? [duplicate]

I'm new to OOP. Can I say Interface is a set of general behavior that may be have and act uniquely by a set of objects that have in common? And Abstract class has similarity with Interface but it have ...
4
votes
2answers
203 views

Is it acceptable to make changes to an interface during implementation?

When writing a library/API for the first time I'll usually start by sketching some ideas on a white-board or loose-leaf while thinking about how different parts of the system interact. This usually ...
6
votes
2answers
729 views

Interfaces and Casting

I recently started working with a shiny new version of a codebase that uses interfaces all over for... basically everything. I think all of our concrete classes implement interfaces. The problem I've ...
1
vote
2answers
283 views

Is this one method interface a good response to this interview question?

Today I received a rejection letter from a company where as part of the interview process they gave a a couple days to respond to the following question (paraphrased): Let’s say say you have ...
2
votes
1answer
57 views

Critique of composition design pattern requiring derived class

I have the following two inheritance chains: BaseQueryBuilder BaseApplication | | | | AppQueryBuilder ...
9
votes
1answer
422 views

How do I structure interfaces when objects only use part of the interface?

I have a project where I have two classes that both require a database access object that updates the same table. The constraints of the framework and project make it so that I cannot combine these ...
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
105 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
171 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
554 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
618 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 ...