I have trouble understanding when multiple classes implements same interface, before i was using concrete classes as DI but after searching and reading i was told that it should depend on abstaraction.So this is my problem:
interface SomeInterface{
public void doSomething();
}
We have two classes that implements interface:
class FirstClass implements SomeInterface{
@Override
public void doSomething(){
System.out.print("First class is doing something");
}
}
class SecondClass implements SomeInterface {
@Override
public void doSomething() {
System.out.print("Second class is doing something");
}
}
And now i have a client where i want to use method from First and Second class:
class ClientClass {
private SomeInterface someInterface;
public ClientClass(SomeInterface someInterface) {
this.someInterface = someInterface;
}
public void testMethod() {
this.someInterface.doSomething();
}
}
Now when i instantiate Client class i can only pass one class in constructor either first or second, and that method will start, but what if i want both method? What is wrong with this design?