Assume the following case:
The price to transport a shipment depends on 2 things
i) the distance from origin to destination and
ii) the weight of the shipment
For example,
If the transportation distance is less than 100 kms, the cost is 10$
If the transportation distance is between 100 and 200 kms, the cost is 20$
If the transportation distance is greater than 200 kms, the cost is 30$
If the shipment weight is less than 10 kgs, the cost is 10$
If the shipment weight is between 10 and 20 kgs, the cost is 20$
If the shipment weight is greater than 20 kgs, the cost is 30$
So, to transport a 50 kg shipment for 500 kms, the total cost is 60$.
Now, the shipment will have a getTotalCost() method, which will calculate the total cost, based on the above rules. It can be done with simple if/else checks, but ofcourse that is the worst way of doing.
Is there any
pattern, which can help me here?
Strategy looks close, but I'm not sure. Any clues.
Many thanks