Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
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
564 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<>();
3
votes
6answers
18k views

Design Patterns - Why the need for interfaces?

OK. I am learning design patterns. Every time I see someone code an example of a design pattern they use interfaces. Here is an example: http://visualstudiomagazine.com/Articles/2013/06/18/the-facade-...
0
votes
3answers
274 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 ...
1
vote
1answer
1k 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 ...
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 ...
101
votes
5answers
85k views

Why were default and static methods added to interfaces in Java 8 when we already had abstract classes?

In Java 8, interfaces can contain implemented methods, static methods, and the so-called "default" methods (which the implementing classes do not need to override). In my (probably naive) view, there ...
0
votes
2answers
215 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
168 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
86 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 ...
0
votes
2answers
80 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 ...
4
votes
1answer
309 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/...
7
votes
2answers
798 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 ...
-1
votes
1answer
305 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 ...
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
2answers
163 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 ...
1
vote
1answer
295 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 ...
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
135 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
188 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
454 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 ...
3
votes
4answers
557 views

Why are inheritance and interfaces restricted to instance members?

Disclaimer: I think the rules are almost the same in most OO languages, but since I'm most familiar with C# I'll be relating to this specific language. I think that the use of attributes and ...
3
votes
1answer
217 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
1answer
385 views

Should we “prefer composition over multiple interface”?

Should we avoid multiple interface if possible? Because I think at most cases a class with multiple interfaces can be replaced with another version with composition and single interface only e.g.: ...
0
votes
1answer
316 views

Should I force “composition over inheritance” rule to class members?

As I know, according to "composition over inheritance" rule, we should avoid reusing a method by inheritance, but how about class members? Suppose I have parent and child classes like the following: ...
-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
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 ...
7
votes
3answers
6k views

Why would an interface override methods of the interface(s) it extends in Java 7?

I was looking at Map and SortedMap documentation from Java 7 and I have realized that SortedMap, which extends Map overrides entrySet(), keySet() and values(). AFAIK, interfaces cannot implement a ...
8
votes
3answers
2k views

How do Text User Interfaces (TUI) work?

I have recently been assigned to port an old COBOL program. I am used to GUIs, and I can't understand how a TUI works. I searched a lot through Google but couldn't find something. I knew that console ...
0
votes
1answer
811 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 ...
13
votes
1answer
852 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: ...
7
votes
2answers
273 views

Java redeclare inherited interfaces?

While working on a small class called FractionNumber I found asking myself if I should implement an interface that I am already implementing. Sounds stupid, I know, but bear with me. My class ...
4
votes
3answers
746 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 ...
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
3k 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(); ...
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 ...
1
vote
5answers
675 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
2answers
458 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
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 ...
0
votes
1answer
153 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 (...
110
votes
5answers
58k views

Why should I prefer composition over inheritance?

I always read that composition is to be preferred over inheritance. A blog post on unlike kinds, for example, advocates using composition over inheritance, but I can't see how polymorphism is achieved....
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 ...
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. ...
15
votes
6answers
13k views

What are the differences between abstract classes, interfaces, and when to use them

Recently I have started to wrap my head around OOP, and I am now to the point where the more I read about the differences between abstract classes and interfaces the more confused I become. So far, ...
4
votes
2answers
217 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 ...
-2
votes
3answers
631 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 ...