0
0
LLDsystem_design~5 mins

Composition over inheritance in LLD - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A'is-a' relationship
B'has-a' relationship
CInheritance hierarchy
DPolymorphism only
What is a key benefit of using composition over inheritance?
AForces tight coupling
BCreates deep class hierarchies
CRequires less code
DEasier to change parts independently
Which is a drawback of inheritance that composition avoids?
AFragile base class problem
BCode reuse
CEncapsulation
DModularity
In system design, what does inheritance represent?
A'is-a' relationship
B'has-a' relationship
CObject composition
DLoose coupling
Which example best illustrates composition?
AA dog is an animal
BA manager extends employee
CA car has an engine and wheels
DA class inherits methods
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.