OO Design Question

I have two types of products - Discounted (10% drive) and NonDiscounted (0%). Each of them can be either LocalProduct / ExportableProduct with export, which attracts a 15% sales tax.

What is the best way to simulate this scenario. I am an absolute beginner in S / W design, I have very limited ideas 1. To have 4 different types of product 2. Use a strategy template and develop 4 different strategies.

Can someone suggest how I can simulate this efficiently using the above options or others.

+3
source share
8 answers

Classes distinguish sets of behavior. So let's take a look at your units in these terms:

  • , / - , : , 0 % . (discount_amount), .

  • / . , , . , , , (, ), ExportableProduct LocalProduct ( ) Product LocalProduct ExportableProduct ( , ).

0

, , , "NonDiscounted" 0 .

+1

:

"" , , , , ..

"" "DiscountRate". 0 . , , 0.

"ExportableProduct" "LocalProduct", "" .

+1

, , , Discounted/NonDiscounted . / "" . . , 10%.

0

(.. ) .

/ /ExportableProduct. , .

, : PricingCalculator, Calculate (, ), . .

. , .

0

: discount local

(), (discount = > price * .9, export = > price * .85 - both = > = > price * .9 * .85)

0

, , .

, , , ( , " " ).

, , , (.. ) , (, "discount_percentage" ).

0

If this is all the behavior you need, just having two boolean elements in your product and including them is the best solution. YAGNI.

But I'm afraid this is just a small part of the bigger problem. And then you have to ask yourself: what makes a product a product (sole responsibility). Taxation and accounting ability are probably two different problems, so your product ends with two strategies.

0
source

Source: https://habr.com/ru/post/1732842/


All Articles