Python composition and object relationships

Composition models a has-a relationship. A Car delegates starting to its Engine instead of inheriting from Engine.

Python
class Engine:
    def start(self):
        return "Engine ready"

class Car:
    def __init__(self, engine):
        self.engine = engine
    def start(self):
        return self.engine.start() + "; car ready"

car = Car(Engine())
print(car.start())
Read the full lesson