When I first read the Strategy Model in "big talk design model", I wondered that there was no difference between the Strategy Model and the simple factory. Why did I sum up the strategy model?
With this question, I went back to my explanation of the policy model. "I read the book for a hundred times, and I saw the difference. First, the simple factory mainly uses the polymorphism feature in object-oriented, that is, any subclass instance can be assigned to the parent class variable, which can be encapsulated in the factory class. When a client application is used, both the parent class and the factory class must be used. The difference between the policy mode and the simple factory is that it has an additional context class, which encapsulatesAlgorithmIn the client, you only need to use the context class to implement different algorithms (Policies) for no need ). To some extent, this mode reduces coupling, that is, the client only needs to understand the context class, regardless of the specific implementation algorithm class.
Let's take a look at the definition:
Policy mode is a method that defines a series of algorithms. From a conceptual point of view, all these algorithms perform the same job, but they only implement differently, it can call all algorithms in the same way, reducing the coupling between various algorithm classes and algorithm classes.
Policy patterns define a series of algorithms, encapsulate each algorithm, and make them replaceable. The rule mode allows algorithms to change independently of customers who use it.
About the strategy model, the big talk design model is easy to understand. Another friend wrote it in the garden.ArticleAlso good.
Http://www.cnblogs.com/justinw/archive/2007/02/06/641414.html (duck-Strategy Mode ))