Python - Composition
Code Life
By Pierre Marsaa
What is Composition?
Inheritance says "a WaterCodemon is a Codemon". But sometimes the relationship is "has a". A Team has Codémon. A Codémon has Moves. This is called composition — objects that contain other objects.
↗️
Loading editor...
↶
↷
A Codemon has a list of Move objects. We can access the move's attributes through the Codémon: myCdm.moves[0].name.
Verify