1 Concept Definition1.1 definition
Defines an interface for creating objects, letting subclasses decide which class to instantiate. The factory method defers the instantiation of a class to its subclasses.
1.2 type
To create a class pattern
2 principle Features2.1 class Diagram
2.2 Advantages
1) good encapsulation, clear code structure
2) High scalability, just modify the factory method or expand a factory class
3) shielding the product class, the caller does not need to care about product class changes
4) highly decoupled, high-level modules only need to know the product abstract class, no need to focus on implementation
2.3 Disadvantages
Increased code complexity
3 .Application Development3.1 Application Scenarios
1) There is a set of similar objects that need to be created
2) You cannot foresee the need to create instances of that kind when coding.
3) the system needs to consider extensibility and should not rely on the details of how product class instances are created, combined, and expressed.
4) factory methods can be used in heterogeneous projects
3.2 Practice Development
Https://github.com/Devonmusa/java-demos/tree/master/src/main/java/com/designpattern/factorymethods
4 Precautions
1). Factory method mode focus on the whole object, not on the process and details
Java design Pattern (iv)-factory method mode (FactoryMethod pattern)