Kamal Mettananda - SCJP 1.4 (98%)
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Kamal Mettananda:
So what is the importance of having Factory Method? I can not understand why Simple Factory is not considered as a good design pattern while Factory Method is considered (even while it uses subclasses to do the work).
But you'd like a little more quality control...
...
you see what you'd really like to do is create a framework that ties the store and pizza creation together[, enforce creation consistency], yet still allow things to remain flexible.
There is a way to localize all the pizza making activities to the PizzaStore class and yet give the franchises freedom to to have their own regional style.
3. It promotes consistency among products. When product objects in a family are designed to work together, it's important that an application use objects from only one family at a time. AbstractFactory makes this easy to enforce.
HFDP p.119:
quote:
But you'd like a little more quality control...
...
you see what you'd really like to do is create a framework that ties the store and pizza creation together[, enforce creation consistency], yet still allow things to remain flexible.
HFDP p.120:
quote:
There is a way to localize all the pizza making activities to the PizzaStore class and yet give the franchises freedom to to have their own regional style.
Kamal Mettananda - SCJP 1.4 (98%)
It's simply a balance: Factory Method needs less code
Simple Factory (sounds to me like that's an Abstract Factory) is more flexible.
Kamal Mettananda - SCJP 1.4 (98%)
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
To be or not to be. It's a question.
Originally posted by Ben Two:
For SimpleFactory, the pizza creation code is written in different Factory, then the prepare, bake, cut, box will be different, that's the reason why the author said 'a little more quality control'.
Kamal Mettananda - SCJP 1.4 (98%)
Originally posted by Ben Two:
Every pizza factory has it's own style of boxing, cutting, etc. That's the point that the author want to use the same boxing , cutting, for all the factory.
prepare, bake, cut and box methods are implemented inside each Pizza subclass, not in any factory.
Kamal Mettananda - SCJP 1.4 (98%)
So in my opinion the only improvement is, No aggregation from PizzaStore to SimpleFactory is needed. In a word, 2 in 1.
"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"
Kamal Mettananda - SCJP 1.4 (98%)
Originally posted by Kamal Mettananda:
Seems the above statement isn't valid?
So what is the importance of having Factory Method? I can not understand why Simple Factory is not considered as a good design pattern while Factory Method is considered (even while it uses subclasses to do the work).
Even the creation and usage is separated well in Simple Factory.
Kamal Mettananda - SCJP 1.4 (98%)
Originally posted by Kamal Mettananda:
Can we consider aggregating two operations like "creation (create method)" and "process (prepare, cut etc methods)" into one class as an improvement?
.
It's a worse design since every subclass of SimpleFactory implement their own process which lose quality control
Kamal Mettananda - SCJP 1.4 (98%)
Pizza orderPizza(String type)
{ Pizza pizza=factory.createPizza(type);
prepare(pizza);
bake(pizza);
cut(pizza;
box(pizza);
return pizza;
}
Kamal Mettananda - SCJP 1.4 (98%)
Originally posted by Kamal Mettananda:
I'm looking for why the Simple Factory is not considered better than Factory method in that example.
You still have to fill in the rest by identifying relationships among the concepts in the problem domain. The method for this uses commonality and variability analysis (CVA). CVA is generally usable, whereas "thinking in patterns" typically is not. I start with "thinking in patterns" because it is an easier process to learn and gives insight into the more useful CVA.
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|