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.