Today, we're gonna build a pizza factory to offering all kinds of pizzas. There are two style pizza stores: NewYork style and Chicago style. They have same bake, cut and box process, but not the same prepare process. Besides, both pizza stores should offering several kinds of pizzas.
use factory method to decouple your client code from the concrete
classes you need to instantiate, or if you don’t know ahead of time
all the concrete classes you are going to need. To use this, just
subclass it and implement my factory method!
use abstract factory whenever you have families of products you
need to create and you want to make sure your clients create
products that belong together.
Often a Factory Method lurking inside the Abstract Factory:
The job of an Abstract Factory is to define an interface for creating a set
of products. Each method in that interface is responsible for creating a
concrete product, and we implement a subclass of the Abstract Factory
to supply those implementations. So, factory methods are a natural way
to implement your product methods in your abstract factories.