Php-Rule Mode

Source: Internet
Author: User

One thing that the policy model has in common with the factory model is good scalability, and the factory model is not much to mention (refer to the previous factory model). The main problem solved by the policy model is that there are multiple policies to choose from, select different policies based on different situations. You can add policies at will without modifying the intermediate modules of the policies. For example, because the formula for calculating the salaries of employees at different levels in the company is different, the finance department will choose different calculation formulas based on different employees. The rule mode is used to solve such problems. The following is an example:

<? PHP
Abstract class salaryabs
{
Public Function calculate (){}
}

Class highsalary extends salaryabs
{
Public Function calculate ()
{
Echo "highsalary! <Br> ";
}
}
Class lowsalary extends salaryabs
{
Public Function calculate ()
{
Echo "lowsalary! <Br> ";
}
}

Class accountant
{
Public Function CAL ($ salary)
{
$ Salary-> calculate ();
}
}

$ Accountant = new accountant ();

$ Accountant-> CAL (New highsalary ());

$ Accountant-> CAL (New lowsalary );

?>

In this way, colleagues in the finance department can settle their salaries by choosing different employee calculation methods. The rule mode is also used in many cases, especially in a wide range of options, and different results must be obtained based on different options. The general rule mode is like this.

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.