Composition
vs
Inheritance
Compound Components
and
Higher Order Components
What is Inheritance?
• Is a relationship
• A car is a vehicle
• A cat is a mammal
What is Composition?
• Has a relationship
• A Car has a engine
• A Person has a name
We now make
airplanes
Inheritance or…?
• Does ObjectB want to expose the complete interface (all public
methods no less) of ObjectA such that ObjectB can be used where
ObjectA is expected?
Inheritance
• A Cessna biplane will expose
the complete interface of an
airplane, if not more.
• Cessna biplane is a Airplane
“Customers want winged planes or birds.”
Composition or…?
• Does ObjectB want only some/part of the
behavior exposed by ObjectA?
Composition
• A Bird may need only the fly
behavior of an Airplane.
• Airplane has fly, takeOff, lift,
thrust, land
• Bird has fly, takeOff, lift, thrust,
land
Code Demo
https://source.datanerd.us/flinehan/compound-high-order/tree/slides/src/
components
At the end of the day Ikea doesn’t sell furniture.
They sell pieces.…
Composition gives us the ability to quickly
create flexible and modern UIs our users and
Product Managers expect.

Composition vs inheritance