Recall & Review
beginner
What is composition in system design?
Composition means building complex objects by combining simpler ones, like assembling Lego blocks to create a model. It focuses on 'has-a' relationships.
Click to reveal answer
beginner
How does inheritance differ from composition?
Inheritance creates an 'is-a' relationship by extending a class, while composition builds objects by including other objects, promoting flexibility and reuse.
Click to reveal answer
intermediate
Why is composition often preferred over inheritance?
Composition avoids tight coupling and rigid hierarchies, making systems easier to change and extend, like swapping parts in a machine instead of redesigning it.
Click to reveal answer
beginner
Give an example of composition in a real-world system.
A car is composed of an engine, wheels, and seats. Each part can be changed independently without affecting the whole car's structure.
Click to reveal answer
intermediate
What problem can inheritance cause that composition helps solve?
Inheritance can cause fragile base class problems and deep hierarchies that are hard to maintain. Composition allows changing behavior by replacing parts without breaking the system.Click to reveal answer
Which relationship best describes composition?
✗ Incorrect
Composition models 'has-a' relationships by combining objects.
What is a key benefit of using composition over inheritance?
✗ Incorrect
Composition allows swapping parts without affecting the whole system.
Which is a drawback of inheritance that composition avoids?
✗ Incorrect
Inheritance can cause fragile base classes that break when changed.
In system design, what does inheritance represent?
✗ Incorrect
Inheritance models 'is-a' relationships by extending classes.
Which example best illustrates composition?
✗ Incorrect
A car composed of parts shows composition.
Explain composition over inheritance with a simple real-life example.
Think about how objects can be built from smaller parts.
You got /4 concepts.
Describe the main problems inheritance can cause and how composition helps avoid them.
Consider why changing a base class can break many subclasses.
You got /4 concepts.