Reading this book makes it easy to understand and understand, so that you can quickly understand the design model. It is indeed a good book. This allows you to inadvertently understand and deepen Oo, as well as the advantages of the design pattern. In the purification process at, you can improve your understanding of the design pattern and the mysteries of the design pattern.CodeThe essence of the design pattern is clearly written. However, I did not write well-developed code for the design model, but I wrote the essence of the design model. As a principle, it is easy for beginners to accept and understand the design model. It quickly leads readers into the world of design patterns.
Below we will write down the core idea of the design pattern, as a record of the essence of the design pattern; completely separated from the book, read the complete book after a week to write all the feelings, in order to deepen the essence of the design pattern memory.
I. Policy Mode
1.AlgorithmIt is encapsulated in various classes, but all classes inherit the same interface, which is responsible for calling implementation and algorithm output. When we need to add an algorithm, we only need to extend a class that implements this interface, and then pass the class as a parameter, and then call the interface in a unified manner to implement it, and pass in different classes, implement the same call to output the corresponding class algorithm;
2. It has three cores: A: implementing the same interface; B: Passing in different classes of encapsulated algorithms; C: unified interface call methods to implement different classes of input, different outputs are achieved for the same disconnection;
3. Objective: To encapsulate multiple algorithm policies.
Ii. Adapter Mode
1. Because a series of classes (1-n) are implemented, a method (they implement the same interface or abstract class), but now there is a new class, we also want to implement the same call methods for that series of classes. The introduced intermediate class is used to further encapsulate the new class so that it looks similar to the series of classes to achieve the same drop-down mode;
2. Two cores: A: There are two different classes, which must be called in the same way. B: introduce an intermediate class and encapsulate the new class to form a behavior similar to the class to be imitated;
3. purpose: to simulate the behavior of another class.
Iii. Singleton Mode
1. To implement an objectProgramOnly one instance is generated during running and introduced. That is to say, a production system produces the same output for one instance and multiple instances. Therefore, a mode is generated to control the waste caused by less instantiation. To prevent multiple instances caused by multiple threads, the lock is generally applied. A: The lock requires a double lock. B: introduce an object-Type Static instantiated object, which is a secondary object, use it for an external judgment (equivalent to a lock, with a delay effect), and add a lock in it; C: Introduce a static read-only instance variable in the form of direct initial, then, determine whether the object exists;
2. Two cores: A: only one instance can be generated; B: prevent multiple instances from exceptions caused by concurrency and multithreading.
3. Purpose: The system produces only one class instance at any time.