1, simple factory pattern classification and usage scenarios:
(1) Simple Factory mode is generally divided into: ordinary simple factory, multi-method simple factory, static method simple Factory (2) Use the scene: In General, the factory model is suitable, where a large number of products need to be created, and have a common interface,can be created through the factory method mode, the first of the following three modes, if the passed string is incorrect, cannot beThe object is created correctly, the third is relative to the second, no instance of the chemical plant class is required, so, in most cases, we willSelect the third-------static factory method mode
2, General simple Factory mode: (1) is to establish a factory class, the implementation of the same interface for some classes to create instances.
Finally, build the factory class:
3, Multi-method Simple Factory mode: (1) The multi-method simple factory is the improvement to the common factory method mode, in the Common factory method mode, if the transmission
string error, the object cannot be created correctly, and multiple factory method patterns provide multiple factory methods, respectivelycreates an object.
4, multiple static methods simple Factory mode:
******************************* The following method is the kingly *************************************
5, Factory method mode (Factoty): (1) Simple Factory mode has a problem, class creation depends on the factory class, if you want to extend the program, you must have the factory class
modification, which violates the closure principle, so, from the design point of view, there are certain problems, the solution is to useFactory method mode, create an interface and create multiple factory implementation classes, so that once you need to add new functionality, directlyAdding a new factory class is OK, and you don't need to modify the previous code.
(2) The benefits of the factory method model: If you want to add a new feature, you only need to do an implementation class to implement Sender interface, at the same time do a factory class, implement Provider interface, OK, no need to change the ready-made code, It's better to be scalable.
java--Simple Factory mode, factory method mode--design mode One