All the following data bits are forged: O (empty _ blank) O Haha ~!!
Business logic: the same system is applicable to the United States and China. The formula is: pay-as-you-go = basic salary + bonus-tax;
For example, China's salary calculation is hand-received salary = basic salary + bonus-tax;
Tax revenue = Basic Salary * 5%; bonus = enterprise's own calculation method
In the United States, the job is calculated as follows: tax = (basic salary * 10% + bonus) * 25%; bonus = calculation method of American enterprises themselves;
Although the total formula for wage calculation is the same (hand-to-hand salary = basic salary + bonus-tax), the specific wage calculation method is different. So the total formula can be abstracted.
SystemCodeLogic explanation:
1. Constant is responsible for providing all the basic data. Here is only the basic salary and the specific reflection class. The ratio of the two taxes is calculated as redundant and is not used for the time being.
2. Abstract Factory is responsible for abstracting high-level business logic. Provide abstract methods for specific factories and the factory to be created.
3. Implement two abstract classes in the abstract factory. The factory is responsible for instantiation, returning specific bonus calculation classes, and tax calculation classes.
4. A specific tax calculation class is responsible for the calculation method. After the calculation is complete, a result is returned.
5. The interface definition abstracts the tax calculation and bonus calculation methods, and implements unified interface exposure to the client .. Because the factory returns a specific class, the class method returns a specific computing class. Computing classes follow the same interface. Therefore, the call at the terminal remains unchanged.
6. Client client call class.
7. Abstract Factory: There are two Abstract METHODS: creatbons (computing bonus) and createtax (computing tax). One factory method uses reflection based on the configuration file, to instantiate the class.
Then, the specific factory implements the creatbons (calculation bonus) and createtax (calculation tax) interfaces. These two interfaces are instantiated and return a specific tax calculation method and bonus calculation method.
Call the abstract factory directly on the client cliet: ibons bons = abstractfactory. getinstance (). creatbons (); itax tax = abstractfactory. getinstance (). creattax ();
Because the abstract factory returns a specific factory class, And creatbons, and creattax under this class all implement the interface ibons, and itax, you can directly call this method. You can directly calculate the bonuses and taxes.