Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

SimpleFactory or FactoryMethod? What is the Difference?

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been gone through SimpleFactory and FactoryMethod examples in a HFDP and I think I have(I still cant belive ) understood both principles, BUT what I didn�t understood is the DIFFERENCE between them in a LOGICAL way.

Technically I really understand, well , actually it is pretty simple
1.
By SimpleFactory we Let the Details be handled by (external)Factory object, we just call a orderPizza Method and we get() our Pizza.

And the client call looks like this:
PizzaStore store = new PizzaStore(new SimplePizzaFactory());
Pizza pizza = store.orderPizza("cheese");

2. FactoryMethod is pretty the same, just makes the PizzaStore abstract and takes the Logic from the (external)Factory object back in the abstract createPizza Method (wich will of course be overridden by NYPizzaStore LAPizzaStore or whatever.)

abstract class PizzaStore {
protected abstract Pizza createPizza(String item);
public Pizza orderPizza(String type) {
Pizza pizza = createPizza(type);
pizza.prepare_bake_cut_box();
return pizza;
}
}

Pretty obvious so far,

But this could be done with the same effect If we created NYFactory and LAFactory
And then in the Client call used: (as the author suggests on the begin of Page 119)

PizzaStore store = new PizzaStore(new NYFactory());
Pizza pizza = store.orderPizza("cheese");


BUT( AND THIS IS WHAT I DON�T UNDERSTAND)in the middle of Page 119
He says that that would be bed idea and that we should use the FactoryMethod approach.
But WHY. What r the benefits? He just lamely explains that we need to tie the store and the Pizza creation(because bed franchises were Atrocious again and�) but in a flexible way. Ok he explains that if we use FactoryMethod we allow the subclasses to decide etc. But that just describes how the FactoryMethod works not what r the benefits of it?


I simply don�t see how the getting back the code in the Method is more flexible then a external Factory object? Imo it is the same thing. In a one way o have to derive the PizzaStore classes and in the other u have to derive FactoryObjects. Same work, same amount of time needed to get it coded, same Effect.

Can someone explain this?
TIA
 
BWA HA HA HA HA HA HA! Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic