Questions tagged [interfaces]

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

0
votes
1answer
70 views

Would you implement an interface to connect to a database?

I found in a book (Learning PHP Design Patterns, Chapter 2, page 25) a text explaining the importance of interfaces in OOP design. The author ended up by giving this example: <?php interface ...
4
votes
5answers
724 views

Newbie question: Should all class public methods come from an interface?

I'm currently learning about TDD techniques, one of the suggestion is to test only public methods and skip the private ones. I have also been reading about Mocking. If I want to mock a certain method, ...
4
votes
4answers
230 views

Should custom exceptions live with the interface or the implementation?

I have an interface IMyService in a class library. I have an implementation of this interface MyService in a separate class library. MyService may raise a custom exception CustomException. Should ...
0
votes
4answers
1k views

Avoiding vtable pointers in objects in C++

In my previous question, it was highlight that implementations of C++ such as GCC must store a vtable pointer in every copy of a class for each parent class which has a virtual function. So a class ...
0
votes
3answers
167 views

Implementing interface using class members

This was just a question I was wondering about in terms of best practice. I am writing a small C++ program that uses an interface to implement a function. In the class that uses the interface (i.e. ...
12
votes
5answers
4k views

Does it make sense to define an interface if I already have an abstract class?

I have a class with some default/shared functionality. I use abstract class for it: public interface ITypeNameMapper { string Map(TypeDefinition typeDefinition); } public abstract class ...
0
votes
2answers
145 views

Use case for interface

While going through some lecture video on interface. I noticed If we don't know about implementation, just requirement specification then go for interface. What can be the scenario? Though I've ...
2
votes
1answer
116 views

Whether to replace mutually exclusive but poorly related properties with an interface

A few years ago I designed a class which had two properties. The two classes ChildA and ChildB had a rich protocol with many properties and methods, but were only distantly related in my model. They ...
1
vote
3answers
1k views

C# How to avoid duplicate code with interfaces where objects have the same behaviour

So a simple example i have: public interface IFollow{ Transform Target {get;} void LateUpdate(); } public A : Monobehaviour , IFollow { public Transform Target {get; set;} public void ...
26
votes
2answers
4k views

Implementation of pure abstract classes and interfaces

Although this isn't mandatory in the C++ standard, it seems the way GCC for example, implements parent classes, including pure abstract ones, is by including a pointer to the v-table for that abstract ...
-1
votes
1answer
170 views

Does Interface Segregation Principle apply to parameters/request objects?

I have recently seen an example of what I think is a clear violation of ISP, but my colleague argued it is easier to use. This is what happened: We had Options class that had 2 fields sent as a ...
1
vote
6answers
622 views

How can I unit-test the presence of specific file contents, through an interface?

I am currently trying to test a file manager class. This class is responsible for keeping track of how long the file is good for. The file will have a date written into it that denotes when it was ...
2
votes
5answers
476 views

Interfaces Everywhere? - Best Practices [duplicate]

There is a discussion at work about the correct use of interfaces in OOP. I have been taught, and always worked from the premise, that interfaces precede concretions and all methods should be dealing ...
1
vote
2answers
143 views

Interfaces for CRUD Classes

In an in-house solution I've been working on, I've been unable to understand the benefit of how interfaces are frequently implemented throughout the project. Which is as follows: Want to do CRUD ...
1
vote
2answers
299 views

Implementing interfaces vs using a base class

I am writing an application in python. The part I am little confused about is providing a little structure to my code. This is the basic requirement of my web application. I have these different ...
-3
votes
3answers
71 views

Naming: How do you call an interface that allows to retrieve items?

Let's say a client need to get a list of products from somewhere. He does not care if that list comes from a cache, from a remote database, from a local database, from the resources or from the remote ...
1
vote
1answer
77 views

Interfaces for waypoints

I have a waypoint class which i use to connect a bunch of other waypoints up. But i also have a special type called a consumer, this is not technically a waypoint but it needs to act like one in that ...
0
votes
2answers
267 views

Use getter interfaces as a way to reuse DTO fields

Assume I have a lot of DTO for a same domain model like this: class User{} //DTO @Value.Immutable interface SimpleUserDTO { getName getAge } @Value.Immutable interface RegisterUserDTO ...
2
votes
1answer
71 views

Should I create seperate interfaces as a way to centralize annotation?

Assume I have these classes: @Entity @Data class Student{ @Size(min = 8) public String name; public int age; ... } @Data class StudentDTO{ @Size(min = 8) public String name; ...
0
votes
1answer
76 views

Avoiding concrete references, should expressing relationships be an exception to the rule?

I have a critical business object GroupMembership that represents the relationship between an user and a group. I have set an architectural policy that critical business objects should avoid ...
1
vote
1answer
1k views

Difference between header files and interfaces

I wanted to know whether the header files in c and c++ have same function as that of interfaces used in Java? If not what is the difference between header file and interface?
1
vote
3answers
263 views

Implementing an ILogger => how to make public some fields that are needed in specific implementation of Logger but not in others

I am implementing a custom ILogger (interface for logging) I have succesfully developed implementations of it with some famous loggers like Serilog or Log4Net. Now i want to create a memory logger, ...
7
votes
1answer
256 views

Should every method in a class be defined in an implemented interface?

I can see how interfaces are very useful to force different classes to have the same functionality. But there are also actions that are bound to a specific class (like updating an unique variable ...
3
votes
4answers
182 views

Circular Interface references

I've heard circular references are generally an issue, however I was wondering if this was true for interfaces that reference other interfaces, for example: IQuestion{ IAnswer getCorrectAnswer(); ...
0
votes
2answers
161 views

Hiding implementation framework usage in an API

I am currenctly trying to create an API for a UI framework, for a new application. This UI framework is internally implemented using an existing framework, let us say JavaFX. I want to hide the ...
1
vote
1answer
103 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 ...
6
votes
2answers
237 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
277 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
3k 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
106 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
97 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
6k 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 ...
0
votes
3answers
191 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
343 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
604 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
102 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
220 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
1k 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
1k 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
1k 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
521 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
249 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
121 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
894 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
172 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 ...