I have a case where my object sometimes has an associated object and other times does not. e.g. my car sometimes has cruise control, and other times does not.
There are two patterns I am debating between - passing an instance, or adding this later. I would like to understand which is the best option (or if there is a better option)
Should I be going this approach:
class Car():
def __init__(self, brand, satnav):
self.brand = brand
self.satnav = Satnav()
class Satnav():
def __init__(self, brand=None):
self.brand = brand
my_car = Car('ford')
or this one:
class Car():
def __init__(self, brand):
self.brand = brand
class Satnav():
def __init__(self, brand=None):
self.brand = brand
my_car = Car('ford')
my_car.satnav = Satnav('tomtom')