I see many people using something like this and call it Factory pattern.
class Factory {
public IProduct Create (ProductEnum type) {
switch (type) {
case ProductAType:
return new ProductA();
case ProductBType:
return new ProductB();
}
}
}
But isn't the real Factory pattern the one where you have one factory for each product type? So when you create new implementation of IProduct you have to create a new factory class and redefine the Create method. Something like in this picture:
Is the first example also Factory pattern or it is something else, and should that be used or not?
Aucun commentaire:
Enregistrer un commentaire