That is to say. 1. Each product has a category. 2. The tax rate only depends on the classification, remains unchanged for a certain period of time, and may be modified manually.
The corresponding countermeasure is to use the bridge mode between categories and products, that is, the category is a field of the product and is not directly derived from the product base class.
After that, the tax rate calculator object is obtained using the abstract factory mode, and the corresponding object is obtained according to the type. Calculator objects are directly implemented by an interface. After the tax rate changes, just change the corresponding objects.
That is to say. 1. Each product has a category. 2. The tax rate only depends on the classification, remains unchanged for a certain period of time, and may be modified manually.
The corresponding countermeasure is to use the bridge mode between categories and products, that is, the category is a field of the product and is not directly derived from the product base class.
After that, the tax rate calculator object is obtained using the abstract factory mode, and the corresponding object is obtained according to the type. Calculator objects are directly implemented by an interface. After the tax rate changes, just change the corresponding objects.