Assume we are in the world of car rental application :)
Let's say that I have 3 types of cars with 2 categories of price:
Car type Price category ------------------------------ Sport High Luxury High Economy Low
Low can change over time, so they should be a separate entity with its own representation in DB.
Every car type has its own price calculation strategy, e.g. renting a
Sport car costs
(High x time_rented) + High_constant_factor.
Below is my current approach:
- one calculation strategy/policy per car type. It encapsulates know-how required to calculate the price, with the following responsibilities: determines constant factor to be used, fetches appropriate price from a repo and finally calculates the total price by applying the right calculation formula. Example:
SportCarPriceCalculationPolicyuses a hardcoded
Carknows nothing about its price or
Is that a good approach? Or should
Car be aware of its price and pass
Low as an argument to a policy and avoid that policy has any dependency on repository?