Interview practice question
Modelling discounts with inheritance or composition
Backend Engineering · OOP and Design Patterns · Intermediate
You are modelling discounts: percentage, fixed amount, buy-one-get-one, and combinations like "10 percent off, but only for members on weekends". Would you use inheritance or composition?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Inheritance explodes with combinations.
- Composition: discount rules + conditions.
- Strategy for calculation, specification for eligibility.
- Composite to combine.
- Data-driven configuration.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.