Free Object-oriented basics lessonsObject-oriented basics · Stage 3 · Abstraction and design choices · Step 2
Composition over inheritance
Holding another object and delegating to it, instead of extending it, and when each is the better design. About 12 minutes.
Which is the strongest reason to prefer composition for reuse?
- AThe class depends only on the other class's public behaviour, and the collaborator can be swapped
- BIt always needs less code
- CIt is faster
Show the answer
The class depends only on the other class's public behaviour, and the collaborator can be swapped. Looser coupling and run-time flexibility.
4 questions on this idea
Short questions that apply the idea to new cases: trace it, work out a number, put steps in order. A wrong answer explains itself.
Answer them in your browserFree account, no card. Your progress is saved, and the idea comes back in a quick review later.
Sign up free to solve