All Questions
Tagged with java interfaces
154 questions
3
votes
3
answers
386
views
How to handle checked exceptions on interface contract in Java
I am starting a project in Java and ran into the following situation. The application requires a persistence layer for a certain document type. This could be a MySql database, an AWS Dynamo DB ...
-2
votes
1
answer
180
views
Vanilla interface implementations. What should I call it? [closed]
Some may think I'm kidding, but I'm really stuck on this
Suppose you have some UserDao interface that you want to implement
What should you call it?
Here are a few points I'd like to make
I firmly ...
1
vote
2
answers
249
views
In Java Interface contracts, does the @throws tag order should be considered?
Concrete example : https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/DataInput.html#readFully(byte[],int,int)
@throws NullPointerException if {@code b} is {@code null}.
is before
@...
7
votes
9
answers
8k
views
Why just "interface segregation principle" but not "method segregation principle"?
According to one definition of "interface segregation principle" that states currently in Two contradicting definitions of Interface Segregation Principle – which one is correct?, a client ...
3
votes
4
answers
515
views
Does "declare the most abstract type" increase coupling actually?
According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, so for example:
public interface Fruit{
}...
0
votes
4
answers
410
views
Are "easier to search for the interface" and "avoid yo-yo to interface to find implementations to fix bugs" reasons to add prefix "I" on interfaces?
According to Should interface names begin with an "I" prefix?, I should not add prefix "I" to interfaces. However, I think prefix "I" in interface may be useful sometimes....
0
votes
1
answer
1k
views
Interfaces vs abstract classes for immutable DTOs
At my org we extensively use @Value.Immutable annotation to generate Immutable classes (usually with builders) for our internal data transfer objects (DTOs). In our codebase I've seen both interfaces ...
2
votes
1
answer
865
views
How to implement interface on Java class I don't own?
I want to allow some Java objects to be translated into a string representation which matches Python or JavaScript objects.
I thought that I could tag all compatible classes with compatibilising ...
1
vote
1
answer
330
views
Gradle/Maven project splitting: interfaces and implementation
Assume we have a single large JVM project (the example is in Kotlin), containing code. As part of a refactoring effort, we are decoupling pieces of the code by splitting the code into multiple modules,...
1
vote
1
answer
234
views
Refactoring instanceOf, moving logic to POJO when it has database interaction
I'm refactoring some old code, I have a lot of istanceOf in the business part:
if (record instanceof RecordA) {
RecordA recordA = (RecordA) record;
...
2
votes
2
answers
462
views
Can access modifiers be completely replaced with programming to interfaces?
If we program to interfaces various parts of the implementation can be effectively hidden. We can define multiple interfaces for a single implementation and use them as needed, instead of 4 fixed ...
0
votes
3
answers
3k
views
How to handle a new method in the interface that is not applicable for all classes?
I am faced with an interesting OOD problem: I have an interface with 3 methods:
interface TestInterface {
String action1();
String action2();
String action3();
}
and 3 classes that ...
0
votes
2
answers
1k
views
What are the tradeoffs between a Union type or a wrapper Class to represent a formatted string argument representing multiple types
Assume there's a public void process method on a Java class called A that currently takes a single String argument id.
class A {
public void process(final String id) {
// Some implementation
}
...
2
votes
3
answers
164
views
Java design: there is two interface: B extends A. A and B have one subclass each, named ABase and BBase, can I make BBase extend ABase?
there is two interfaces A and B:
public interface A {
}
public interface B extends A{
}
A and B have one subclass each:
public abstract class ABase implements A{
}
public abstract class BBase ...
2
votes
2
answers
177
views
How to structure classes for two distinct use cases that share key parameters
I have a Java application that needs to generate mathematically-defined 3D shapes for a voxel world (Minecraft specifically, but that's not important to the discussion). These include sphere, ovoid, ...