Class composition and inheritance

How can it use either rule without being a discount rule itself?

Examples

Worked example

Input
Checkout needs to switch between two discount rules.
Expected output
Give Checkout a DiscountPolicy field.

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

The checkout delegates discount calculation to its collaborator rather than inheriting one specific rule.

Back to the lesson