Java design mode, java design mode pdf

Source: Internet
Author: User

Java design mode, java design mode pdf

[This article is my own learning notes. You are welcome to repost it, but please note the Source: http://blog.csdn.net/jesson20121020]

The above three sections enable sorting of all types from the initial sorting of integer arrays to the final sorting of all types by defining their own comparator as needed, different algorithms are implemented, and they are individually divided into a class. You can choose based on your actual needs and have high scalability. In fact, the policy mode is used here.

Strategy pattern Strategy is an object behavior pattern in design patterns. It mainly defines a series of algorithms and encapsulates these algorithms into separate classes one by one, such as the comparator in the preceding three sections. The rule mode is widely used. For example, the school traffic change chart may have two implementation methods: Split the line, and pie-like representation. For example, the Cat-type height comparator, weight comparator, in the preceding three sections. By defining different policies, we can freely switch the algorithm during the program running.

The core part of the actual policy mode is the use of abstract classes or interfaces. When you need to change the policy mode, the amount of code modified is small and fast.

The policy mode is similar to the factory mode. The policy mechanism is relatively simple and easy to understand, and can be switched freely at runtime, while the factory mode is mainly used to create objects.

The rule mode is applicable to the following scenarios:

1. save files in different formats

2. compress files with different algorithms

3. capture images using different algorithms

4. output images of the same data in different formats, such as curves and bars.

......

In a word, the policy mode is suitable for the situation that "the same function must be implemented using different algorithms and formats" encountered in actual development. The decision of policy mode lies in the user. The system itself provides implementation of different algorithms and encapsulates various algorithms. Therefore, policy modes are generally used in algorithm decision making systems. external users only need to decide which algorithm to use.

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.