[Cs3] CS3 - Lab 8 Question
Mikhail Nesterenko
mikhail at cs.kent.edu
Thu Mar 13 21:00:25 EDT 2014
> Product* Factory<Product>::make(char figType, int size, char fillType, char fillChar){
> Product *retProduct;
> Fill *ptrToFill;
>
> // determine the fill type
> if(fillType == 's'|| fillType == 'S')
> ptrToFill = new Solid(fillChar);
> else
> ptrToFill = new Hollow(fillChar);
>
> // determine the figure type
> if(figType == 't' || fillType == 'T')
> retProduct = new Triangle(size, ptrToFill);
> else
> retProduct = new Square(size, ptrToFill);
>
> return retProduct;
> }
This solution defeats the purpose of the factory pattern: the
factory recognizes the type of product it manufactures. The problem
with this is that it requires a modification of this function in case
a new figure type is added.
See if you can recode this such that the abstract factory method is
unaware of the type of concrete product it produces.
Hint: "new" may be parametrized by the template's type parameter.
Thanks,
--
Mikhail
More information about the cs3
mailing list