Python Quest

Track 11 · Lesson 9 of 12

Composition

Build objects out of other objects, delegate work to the parts, and prefer has-a composition when inheritance doesn't fit.

About 40 minIntermediate4 exercises

You will be able to

  • Recognise a has-a relationship and model it by storing objects as attributes
  • Delegate work from an object to the objects it contains
  • Build objects that hold and summarise lists of other objects
  • Explain why composition is often a better choice than inheritance

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.