First, the Strategy model
Policy mode: Encapsulates easily variable algorithms that can be replaced by each other.
GoF "design mode" says: Define a series of algorithms, encapsulate them one by one, and make them interchangeable. This pattern allows the algorithms to be independent of their customer changes.
For example: A push service class, push the way, can be divided into: QQ Push, mailbox push, App push, PC plug-in push.
Here are two points to be told:
1, push the way can replace each other;
2, these push the way is simply belong to the push service this class itself.
Think about it. Key words: replace each other
Second, the command mode
Command pattern: Solving "behavior requestor" and "behavior implement" usually presents a "tight coupling" problem.
GoF "design mode" says: Encapsulate a request as an object, allowing you to parameterize the customer with different requests, queue up requests or log requests, and support revocable operations.
For example, an intelligent remote control, can be controlled home lights, electric kettles, routers, these open and close.
We use Strategy mode?
OK, remote control class, abstract open, abstract off. But how do you get the electric kettle?
So in the final analysis: definition is important. The command pattern has two important roles-the requestor and the implementing person.
The remote control is the requestor, these appliances are the realization. The key is the opening and closing of the electric kettle can not be replaced AH.
Three, template method: to be supplemented
Command mode & Policy mode & Template Method