I. Creation Mode:
1. Brief Introduction
Singleton mode: solves only one problem of class instances.
Abstract Factory: solves the problem of generating instances that replace multiple classes at the same time.
Builder mode solution: the complex composition of each part of an instance
Factory method: solves the problem of frequent changes in instance creation.
Prototype: it is also a late binding problem.
2. Possible implementations
Abstract Factory, it is easier to solve problems such as database connection during game style conversion. For example, the style of the room layer in the game, from the European style to the Chinese style, the classical style to the modern style, there are a lot of classes to be replaced, you can use abstract factory, it is more practical to solve such problems. Abstract Factory is used for changing multiple objects.
The builder mode is complex for a structure, but composed of independent parts (the number of parts is random), just like the building blocks of a child. To build a house, you may have two roofs, the number of roofs and windows is not fixed, and the final house is definite. Some interfaces like this are fixed (that is, they all use the same module, such as the window module and the roof module), but the builder mode is quite suitable for complex components.
Factory method, I have seen two implementation methods. The first one is encapsulation change point. For example, testing, comparing and testing a car, testing a Mercedes-Benz today, and testing a BMW tomorrow, the specific content of the operation is constantly changing. To encapsulate this change, you can use the factory method. The implementation is like abstract factory. Of course, it is like abstract factory. Why? In fact, it only solves the problem by replacing multiple (batch) in the abstract factory method with one. Second, I think this is more common, that is, under the same operation, such as the device type, collector, gateway, and so on, there may be multiple different categories, multiple different classes must be used at the same time. The example of testing a car is that the factory also needs to test both Benz and BMW. The testing method is the same, but the implementation details are somewhat different. In this case, the factory method can also be used. The specific implementation is to input different names and create different objects. Such a factory method. Factory. buildercar ('benz'), factory. buildercar ('bmw ').
Prototype: clones objects to realize true polymorphism. This is a bit like a factory method, or an abstract factory method, just integrating the factory into the specific class content. The specific implementation scenarios are still under consideration.