mercredi 20 juillet 2016

siomple factory and IOC

I have a class A{} class B:A{} class C:A{} and class D{} D has methods that need to to use B and methods that need to use C.

in the future I will probably have more classes that inherit from A that Dwill need to use

should D have a constructor like:
public D(A b, A c) and will be called in injection (new B(),new C())

or should A get a simple factory (F) that will return the correct class.

and then the constructor will be public D(F f)

F will have a CreateInstance method that will get enum and return the correct type.

full injection would keep all in the composition root. simple factory would simplify the constructor.

Aucun commentaire:

Enregistrer un commentaire