A
A
Andrey Prozorov2019-08-13 13:41:05
OOP
Andrey Prozorov, 2019-08-13 13:41:05

How to properly architecture an order?

There is an order. There is an order calculation method. The method is needed in many places. You can place the method in the order entity or in the orders service (or the order calculator, or your own version).
And two situations:
1) The cost of the order depends only on its own properties
2) The cost of the order depends on any crap for example external api, discounts, day of the week
Where would you place the method for calculating the cost of the order in these two different situations?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Northern Lights, 2019-08-13
@i_d_1

There is an order calculation method. The method is needed in many places.
this is the mistake - all in a heap. It is necessary to make the calculation not a black box, but a customizable user-friendly interface:
$discountCalculator = new discountCalculator(\ListItems $items);
$discountCalculator->addCondition(new SimpleDiscount());
$discountCalculator->addCondition(new BlackFridayDiscount());
$discountCalculator->addCondition(new ByDateDiscount('last day of this month'));
$discountCalculator->addCondition(new ApiDiscount());
$discountCalculator->calculate();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question