Hi,
what is the difference between factory and abstract factory method?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Apr 5, 2012, 3:43 AM
Factory
Define an interface for creating an object but let subclasses decide which class to instantiate.
This means that an abstract Creator class defines an abstract create method (or provides a default create method) which returns an abstract Product.
A ConcreteCreator class implements the abstract create method to return a ConcreteProduct. This enables the Creator to defer Product creation to a subclass.
Factory Method is often used in the Abstract Factory pattern to implement the create methods
Pros
* shields clients from concrete classes
*the Creator create method can be coded to return a default Product
cons
* coding a new Product means writing two classes
* one for the concrete Product and one for the concrete Creator
* static
* inheritance based
Abstract Factory:
Provide an interface for creating families of related or dependent objects without specifying their concrete classes
This means that a family of abstract create methods are grouped in an AbstractFactory interface.
ConcreteFactory implementations implement the abstract create methods to
produce ConcreteProducts.
Pros.
* shields clients from concrete classes
* easy to switch product family at runtime
* just change concrete factory
* keep it in the family
* enforces product family grouping
Cons.
* adding a new product means changing factory interface + all concrete actories
hope this help.
SenthilkumarPosted Apr 4, 2012, 6:48 AM
Difference between factory and abstract factory:
http://c2.com/cgi/wiki?AbstractFactoryVsFactoryMethod
http://objectmix.com/object/10922-difference-between-factory-abstract-factory.html
If you want to know all the patterns then
http://www.dofactory.com/Patterns/Patterns.aspx
VulpesPosted Apr 4, 2012, 6:08 AM
http://stackoverflow.com/questions/6409926/factory-vs-abstract-factory-design-pattern