Questions tagged [interfaces]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
104 views

Struggling trying to create interface for Janrain-like services

We are using Janrain in our app, but I have to create an interface to make this service easily replaced (because Janrain is so custom!, it does have common things in Oauth however) However, I'm ...
28
votes
2answers
3k views

What is the name of the following (anti) pattern? What are its advantages and disadvantages?

Over the last few months, I stumbled a few times over the following technique / pattern. However, I can't seem to find a specific name, nor am I a 100% sure about all its advantages and disadvantages. ...
6
votes
2answers
244 views

Common name for an interface that has Created and Modified fields

I'm trying to figure out is there a common name for object's interface if our intent is to show that this group of objects has date of creation and tracked dated of last modification. It is an entity ...
0
votes
2answers
278 views

Classes as parameters

I would like to write a data structure implementation in Java that uses caches as a core part of its functionality, and I would like the user to be able to provide their own cache implementations that ...
0
votes
2answers
4k views

Not implemented Methods of Interfaces [closed]

I found an interesting quote in my book with which I learn Java: Manche Methoden der in diesem Kapitel beschriebenen Schnittstellen sind in der Dokumentation als optional gekennzeichnet. Bei ...
2
votes
1answer
108 views

When should concrete public methods be used if implementing an interface?

Recently I have been trying to avoid down-casting object types from an interface type to their concrete types, and 'if' statements that check for an objects concrete type at run-time. This has made me ...
4
votes
1answer
98 views

Converting Interfaces to Sub types. Is this bad SE?

In the company I work for, I keep seeing IManager interfaces being converted into their real types and lots of "instanceof / TypeOf" if statement checks. For example: IManager manager // passed to ...
1
vote
0answers
25 views

How would I go about developing an interface that would allow integration of 6 other models?

I am new to programming, I have been trying to get my head around this. Context My project is about defining investment packages for various construction projects within a country based around an ...
6
votes
3answers
7k views

Writing 'interfaces' for static classes

I'm writing a postcode validation library, so that I can call a helper method var result = Postcode.IsValid(postcode, country) To that end I need to have 'classes' that represent supported countries ...
3
votes
4answers
843 views

Implicit optimization versus explicit optimization

To explain what I mean, let me start with an example. Consider a deque that supports O(logn) concatenation with another deque and O(n) addition of n elements at one end. This dequeimplements a ...
0
votes
3answers
192 views

Documenting my code using generic Design Patterns interfaces

Background I've been thinking about documenting design patterns in our code by setting up interfaces for the common design patterns so that when people read my code it would be clear that I am using ...
0
votes
3answers
349 views

Send records using async or sync way

I have bunch of keys and values that I want to send to our messaging queue by packing them in one byte array. I will make one byte array of all the keys and values which should always be less than 50K ...
3
votes
3answers
626 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;...
10
votes
3answers
6k views

Using Interfaces for Loosely Coupled Code

Background I have a project that depends on the usage of a certain type of hardware device, while it doesn't really matter who makes that hardware device as long as it does what I need it to do. With ...
4
votes
2answers
734 views

Is Dependency Inversion a valid alternative to the pImpl idiom?

If I want to present to the user of my code an interface, that is unlikely to change, I can write only the public part of the classes in public headers and have a single private pointer to another ...
6
votes
2answers
1k views

Handling interface segregation in C++

I'm designing a "view" handling system for a game. The goal is to be able to have different "views" that can be shown in sequence or stacked on-top of each other. For example, the initial splash ...
36
votes
11answers
9k views

Are abstract classes / methods obsolete?

I used to create a lot of abstract classes / methods. Then I started using interfaces. Now I am not sure if interfaces aren't making abstract classes obsolete. You need a fully abstract class? ...
1
vote
0answers
103 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 ...
31
votes
3answers
11k views

If I implement an Interface, is it called an Inheritance?

If my class implements an interface then can I say that I'm following inheritance? I know that when a class extends another class then it's inheritance.
2
votes
2answers
277 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 ...
5
votes
1answer
235 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 ...
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 ...
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 ...
-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 ...
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<>();
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
257 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
946 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 ...
97
votes
5answers
84k 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
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
142 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 ...
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 ...
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/...
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 ...
-1
votes
1answer
301 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 ...
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
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 ...
1
vote
1answer
273 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 ...