Big talk design pattern book Note 2-strategy Pattern

Source: Internet
Author: User

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 ))

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.