Hi Kamal
Ofcourse I read your reply.
Now I'd like to explain more on the difference between SimpleFactory and AbstractPizzaStore which is actually a Abstract Factory using Template Method.
with SimpleFactory, you can refer to Page 117
PizzaStore aggregate a SimplePizzaFactory, SimplePizzaFactory create and return an abstract class Pizza with prepare, bake ,cut, box operations, and CheesePizza, VeggiePizza extend the abstract Pizza, so they have their own prepare, bake ,cut, box which is different.
Before:
class NYSimpleFactory extends SimpleFactory
{
Pizza createPizza(String type){
//creates Newyork specific
Pizza pizza;
if (type.equals("cheese")) pizza=new NYStyleCheesePizza();
return pizza;
}}
class PizzaStore {
public PizzaStore(SimpleFactory factory)
{ .... }
Pizza orderPizza(String type)
{ Pizza pizza=factory.createPizza(type);
pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
return pizza;
}
}
After:
public abstract class PizzaStore
{
abstract Pizza createPizza(String type);
public Pizza OrderPizza(String type)
{
Pizza pizza=createPizza(type);
pizza.prepare();
pizza.bake();
pizza.cut();
pizza.box();
return pizza;
}
public class NYStylePizzaStore
public Pizza createPizza(String type)
{
if (type.equals("cheese")) return new NYStyleCheesePizza();
......
}
Now the biggest different of two solution is two class PizzaStore and SimpleFactory combined into one class, the Concrete PizzaStore.
Client invocation change from
SimplePizzaFactory factory=new NYStylePizzaFactory();
PizzaStore store=new PizzaStore(factory);
store.orderPizza("cheese");
into
PizzaStore store=new NYStylePizzaStore();
store.orderPizza("cheese");
If you read the second to the last paragragh of page 119
"Rethinking the problem a bit, you will see that what you'd really like to do is create a framework that ties the store and the pizza creation together, yet still allow things to remain flexible"
So in my opinion the only improvement is, No aggregation from PizzaStore to SimpleFactory is needed. In a word, 2 in 1.
And for the quality control, Let's assume every PizzaStore has their code fragment of cutting, baking ,etc. The evidence is the first paragragh in page 119
"the franchises are were using your factory to create pizza, but start to employ their own procedure for the rest of the process, bake differently, cut differently, use different box"