C # object-oriented model design 23rd Lecture: startegy policy model (Behavior Model)

Source: Internet
Author: User

(According to the msdn webcast courses)

This is a behavior-oriented design model that is widely used.

Objects may often need different typesAlgorithm, But if the change is frequent, the type will become very fragile.

As shown inCubeTake, take different cross sections, then its area calculation method will be different, need to use different algorithms.

So, how can we design Algorithms Dynamically without changing the method during runtime? Decouples algorithms from objects for dynamic loading.

In C #, the following technical means can be dynamically loaded to support runtime changes:

Virtual functions, interfaces, delegation, reflection

Gof: defines a series of algorithms, encapsulates them one by one, and enables them to replace each other. This pattern allows the algorithm to be independent of the changes in the customer system using it.

An example with no rule mode adopted:

After the policy mode is adopted, the algorithm policy and the specific object are separated, so that different algorithms can be implemented by inputting different policy objects in the same object, this allows you to dynamically change the algorithm.

<End>

Related Article

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.