Factory mode concept:
1 instantiate the object, replacing the new operation with a factory method.
2 Factory mode includes factory method mode and abstract Factory mode.
3 Abstract Factory mode is an extension of the factory method pattern.
Factory mode Intent:
1 defines an interface to create objects, which subclasses decide which classes to instantiate.
2 instantiation work is given to subclasses to implement.
Suitable for the Factory mode situation:
1 Create a similar set of objects.
2 You cannot foresee which class instance needs to be instantiated.
3 Consider extensibility and do not rely on product class instantiation details.
Factory method Pattern Class diagram:
Abstract factory Pattern class diagram:
The factory method model produces multiple products of the same class, and a specific factory in the abstract factory model produces a product family divided by multiple product hierarchies.
Resources
Factory mode Overview
Java design mode Factory mode