Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
57 views

How to name a function(non-default image orientation)?

I have a C++ interface for video provider. Frames can be rotated (Portrait/Landscape) as a result of platform-specific functions. enum class EFrameOrientation { KUp, // default orientation ...
11
votes
1answer
2k views

Why doesn't CharSequence define contains(CharSequence)?

This applies to to both Java SE & Android, as the contracts are identical. CharSequence documentation for Java SE CharSequence documentation for Android CharSequence does not define a contains(...
1
vote
1answer
110 views

How should we verify that client classes use their dependencies correctly?

In J.B. Rainsberger's discussion of collaboration tests he describes how tests for "clients" (users of a particular interface) should have two parts to their test. Does the client ask the right ...
2
votes
2answers
2k views

Java interface for comments only. Good practice?

I have a class that has loads of functions, and I can't divide it in multiple class : Class A { // attributes /** * Descriptive of foo * * @param i ... * @param j ... ...
0
votes
2answers
532 views

What is the difference when create Set<T> in java [closed]

When creating a Set in Java, what's the difference between the following? Which one should I use, and why? Set< T > set = new HashSet<>(); HashSet< T > set = new HashSet<>();
0
votes
3answers
258 views

Is it generally okay to use concrete classes from OS libraries on an interface?

I do believe that my question is similar to: Is it OK for interfaces to depend on concrete classes? and see/understand what the answer explains about how the dependency-inversion principle should be ...
2
votes
2answers
122 views

Enforcing the way of object construction in interface a good practise or not?

As far as I understood it is already not possible languages like Java, C# etc. Because the method name of defining constructor in these languages must be same with the class name. That because I'll ...
1
vote
1answer
958 views

How to avoid the static_cast/dynamic_cast in `Abstract Factory` design pattern?

We are using Abstract Factory design pattern in our project, as the project became complex, most of the time the concrete class functionality need to separate to multiple class. As the following code ...
-1
votes
1answer
176 views

Enable access to objects via Introduce Parameter Object or interface

I am working with multiple commands that are executed in order (and possibly have sub commands as well) which can be desribed like this: interface ICommand { void Execute(); } abstract class ...
17
votes
6answers
6k views

What does the author mean by casting the interface reference to any implementation?

I am currently in the process of trying to master C#, so I am reading Adaptive Code via C# by Gary McLean Hall. He writes about patterns and anti-patterns. In the implementations versus interfaces ...
6
votes
6answers
2k views

Coding to Interfaces vs Abstract Inheritance

Inheritance vs coding to an interface is something I have wondered with respect to proper architecture design but actually have not run into an problems when using abstract inheritance over coding to ...
0
votes
2answers
205 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
143 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
278 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
78 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
733 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
300 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
3k 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
302 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 ...
13
votes
3answers
20k 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
4k 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
55 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
275 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
130 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
184 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
390 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
2k 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
757 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
808 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
701 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
162 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
151 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
67 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
373 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
625 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
152 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
164 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
564 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
205 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
761 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 ...