I've a domain package which has an interface called MyInterface. I've a factory class called MyFactory which should help in creating instances of clssses implementing MYInterface at runtime.
Domain Layer
interface MyInterface{
//some Domain specific methods here
}
class MyFactory{
public static MyInterface getInstance(Object resource) {
//return MyInterfaceImpl instance via the methods
this Object can also be a Class argument, where I do Class.forName("").newInstance(); but this is a bad design.
}
class DomainServiceImpl {
public void domainMethod(Object res){
MyInterface i = MyFactory.getInstance(res);
}
Service layer
class Class1 implements MyInterface {
}
class Class2 implements MyInterface {
}
class ServiceClass {
public void service(){
domainServiceImpl.domainMethod(Object res);
}
So how should I write my factory method in domain layer to get the correct impl instance of service layer without using if/else or switch and avoiding cyclic dependencies. Options: can use reflections but not sure how to.
Aucun commentaire:
Enregistrer un commentaire