O'Reilly Forums: Simple Factory Vs Abstract Method Factory - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Simple Factory Vs Abstract Method Factory I don't really get the difference

#1 User is offline   fadeh 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 20-January 12

Posted 20 January 2012 - 12:53 PM

At page 135 it's stated that the main difference between the two is that: "[...] By subclassing the PizzaStore class, you decide what concrete products go into making the pizza that orderPizza() returns. Compare that with SimpleFactory, which gives you a way to encapsulate object creation, but doesn't give you the flexibility of the Factory Method because there is no way to vary the products you're creating".
I found that this isn't true at all. In fact you can have something like that (it's c# but almost the same):
    public class PizzaStore
    {
        IPizzaFactory Factory;
        public PizzaStore(IPizzaFactory factory)
        {
            this.Factory = factory;
        }

        public Pizza orderPizza(string type)
        {
            Pizza pizza = Factory.createPizza(type);
        }
    }

And you can have the very same pros from a factory method pattern. You can vary the products by varying the concrete PizzaFactory you supply. So what's the point? Am I missing something?

Thank you
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users