Use object-oriented technology to solve the product discount problem (2)

xiaoxiao2021-03-06  50

We now look at the information to use to use the CodePromotion class in the checkout method. First, getpromotionamount is required, and we hope to know someone but why do you want to discount, so getDescription this method is also It is to be, and user () is the process of using the promotion code. So a better way is to define an interface. The parameter type in the checkout method makes this interface, not the ColdPromotion class, so that we can implement this interface, whether it is the discount. What we need to do is to let our new discounts implement this interface. Here is the definition of this interface:

Interface Promotable {public float getpromotionamount (Float Totalcharge) public boolean isvalidate () public void use () public string getdescription ()}

I thought that I couldn't worry soon, but I would like to have a concern, if a certain day salesman made a heart-hearted madness, how many discounts use? In fact, this problem can also be solved, that is, we are passing in Checkout, but a vector or promotable array. Before checkout, we put all the discount information in this Vector in Checkout. During the process, traverse this vector (or array). Even we can write a management class specifically managed, let him complete the creation of various discount information, calculate the total discount, record the reasons for various discounts, and make a discount process work. How to implement it will be based on the good evil.

Copyright: IDILENT website reproduced please indicate the author's other reprint, please contact the author (iDilent@yahoo.com.cn).

转载请注明原文地址:https://www.9cbs.com/read-115548.html

New Post(0)