All Questions
31 questions
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
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 ...
3
votes
2
answers
179
views
Composing and Inheriting from the Same Type
To start off with an example: I have a read-only Repository used for getting arbitrary values. This behavior can be implemented multiple ways.
I also want to allow opt-in mutation of the repository's ...
9
votes
4
answers
3k
views
OOP Design considering no modifications to existing design
The question is:
interface Animal {
void eat();
}
class Lion implements Animal{
public void eat(){
//do somethng
}
}
class Test {
public static void main(String[] args) {
...
1
vote
2
answers
329
views
What goes on behind the scenes when data is passed through the use of interfaces?
I understand an interface is a contract and if a class implements that interface, it must define those abstract methods from the interface. What I don't understand is, how is data passed between two ...
2
votes
1
answer
241
views
What are Java Interfaces used for? (multiple choice question)
I'm a beginner studying interfaces in Java through some quizzes and I came through this question:
What are Java Interface used for?
I can opt among one of the following three choices:
A. They're ...
-1
votes
2
answers
2k
views
How to implement a different behaviour for a method without changing the interface?
I am creating a small project that implements an interface in Java. I am not allowed to modify the interface, which means I can't change the functions in my class that implements the interface.
...
1
vote
4
answers
352
views
Interface with similar methods
I'm currently taking over a project that has a common pattern of interfaces like this:
public interface EmailService {
void sendInvitationEmail(Payload payload);
void sendNotificationEmailToAdmin(...
4
votes
2
answers
111
views
How are settings structured when they can be configured in diffferent ways?
Suppose of this question the following:
I'm in full control of this project
I'm writing a media player
Obviously, a media player will allow a user to adjust the volume, so I might have a class that ...
1
vote
2
answers
655
views
Does it make sense to implement a Class Factory design in an RPG Character Creation module
I'm a self-taught Engineer, a beginner in Java and I am trying to create a Dungeons and Dragons character creation module for a bigger game to solidify my understanding of core concepts while learning ...
3
votes
1
answer
6k
views
Using generics on interfaces when implementation is not generic
Is it acceptable practice to put generics on an interface when the implementation will not be generic? Lets say that my project will have many classes that read data from the database. I may make a ...
2
votes
1
answer
138
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
2
answers
297
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
3
answers
368
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
2
answers
4k
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 ...