I have read about Factory Pattern where it is used to create Objects on the fly based on some conditions. However, is it a norm to create Service classes based on those conditions.
class ServiceFactory {
DummService1 A;
DummService2 B;
DummService3 C;
Service getService(String condition) {
switch condition:
case A:
return new A()
case B:
return new B()
case C:
return new C()
}
}
class DummyService1 implements Service{}
class DummyService2 implements Service{}
class DummyService3 implements Service{}
Above is an example. Also, I am trying to do this in Spring, so these service classes are Autowired (did not want to complicate the above example with Spring Specific syntax).
Aucun commentaire:
Enregistrer un commentaire