Java record-66-Rule Mode

Source: Internet
Author: User

Java record-66-Rule Mode
Strategy: the Strategy model embodies two basic object-oriented design principles: l encapsulation of the concept of change; l Programming Using Interfaces rather than interface implementation; interface-oriented programming policy mode definition: l defines a group of algorithms, encapsulates each algorithm, and makes them interchangeable; l The Policy mode enables these algorithms to change without affecting each other when the client calls them. The significance of the Policy mode is as follows: l The Policy mode enables developers to develop software consisting of many replaceable parts, and each part has a weak connection relationship; l The weak connection feature makes the software more scalable and easy to maintain; more importantly, it greatly improves the reusability of the software; composition of the policy model: l abstract policy role: strategy class, usually implemented by an interface or abstract class; l specific policy role: encapsulates related algorithms and behaviors; l environment role: holds a reference of the Policy class and finally calls it to the client. Implementation of policy mode: l the purpose of policy mode is to encapsulate each algorithm into an independent class with a common interface for mutual replacement; l The Policy mode allows the algorithm to change without affecting the client. Policy mode can be used to separate behaviors from the environment. l The Environment class is responsible for maintaining and querying behavior classes, and various algorithms are provided in specific policies. Because the algorithm and environment are independent, modifications to the algorithm do not affect the environment and the client. Write the policy Mode Step: 1. define a public interface for the policy object; 2. write a policy class that implements the above public interface; 3. save a reference to the policy object in the class using the Policy object; 4. in the class using policy objects, set and get methods (injection) of policy objects or assign values using constructor methods are implemented. disadvantages of policy pattern: 1. the client must specify all the policy classes and decide which policy class to use. 2. causes many strategies. (The Factory method can solve this problem)

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.