Design Guru, on 31 May 2012 - 03:10 AM, said:
This is an abstract fatory pattern implementation.
We have two factories here Sedanfactory and hatchbackfactory
The Cardactory is the abstract factory used here, thoug i could not find the defanition for that.
The abstract factory carfactory could point to either hatchfactory or sedanfactory at runtime.
We have abstract product Icar her ( normally we use an abstract class to define the abstract produt and not an interface)
sedan and hatchback are two concrete products
This is just a factory method. Just because he is using an abstract object doesn't mean it's an abstract factory. In this example we just have a single object being abstracted out: the ICar, through an abstract method call. This is basically the same example as in the HFDP book, except he is making cars instead of pizzas.
Abstract Factory deals with families of related objects. For example, in the GoF book, you have a an abstract Widget factory that, in turn, has factories for windows, and scroll-bars, etc. HFDP discusses this in terms of ingredients. Each pizza has a different creator for crust, cheese, etc. and they are all grouped into the the Ingredient Factory. Abstract Factory is more of a factory of factories.