1. Introduction to the simple factory Model
1.1>, definition
The simple factory mode defines a factory class, which can return instances of different classes according to different parameters. The created instances usually have a common parent class.
In simple factory mode, only one factory class is required.
The simple factory mode is also called the static factory mode. The factory class is a static class or contains a static method.
1.2>. Usage Frequency
Medium
2. Simple factory mode structure
2.1>, structure chart
2.2> participants
Participants in the simple factory model:
Abstract product: Abstract product class. It abstracts and extracts common code of a specific product class and encapsulates it in an abstract product class.
◊ Concreteproduct: A product class that encapsulates the code of various product objects to be created into a specific product class.
Factory: A factory class that provides a factory class for creating various products and a factory method for creating products in the factory class, this method can create different product Objects Based on different input parameters.
Consumer Client: client class. You only need to call the factory method of the factory class and input the corresponding parameters to obtain a product object.
3. Simple factory mode structure implementation