Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
3
votes
3answers
635 views

How to decouple code behind with business logic?

I'm having a hard time to decouple two classes. I have my code behind (will call it "class A") that I use to tweak the interface (defined in xaml). Next I have a class B that is only logic. But ...
1
vote
2answers
2k views

Can the Decorator pattern be used without an interface?

Most of the resources I've seen about the Decorator pattern look like the following: interface Tea { public double cost(); } class BasicTea implements Tea { public double cost() { return 1.99;...
1
vote
0answers
104 views

Can we break CQS to get some DRY?

In our codebase we have a lot of controllers with a very similar structure: @my_model.update_owner(something) if @my_model.update_attributes(params) return render_object(@my_model) else ...
5
votes
1answer
240 views

Properly integrate an IDL into multiple git repositories

IDLs like Protobuf, flatbuffers, Cap'n Proto or Thrift allow communication over standardised interfaces between otherwise independent projects. Most often, these projects will be developed in ...
1
vote
2answers
2k views

Why we use interface since we need to implement the method in our derived class [closed]

I have read the replies from those post(Why are interfaces useful?) and (Why use an interface when the class can directly implement the functions?), which is the similar question as my this post. But ...
0
votes
3answers
3k views

C# Implementing multiple, disparate interfaces in a single base class

(This is probably a dupe, but if so I haven't seen it yet, although it may be Best practice for encapsulating a parameter that requires multiple interfaces to be implemented, but that question doesn't ...
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
536 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
268 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
982 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
179 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
206 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
147 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
281 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
750 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
302 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
303 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 ...
14
votes
3answers
21k 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
279 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
133 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
397 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
773 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
158 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
816 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
710 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
68 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
401 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
641 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. ...