When creating a new instance (say A) of a class, I want an instance (say B) of another class to be an optional argument of the constructor. If B is given as an argument, then I want the constructor of A to specify that B belongs to A. If not given as an argument, I want my constructor to create a NEW instance (say C) of the same class as where B belong to and specify that this new instance belongs to A.
More specifically, I'm working on an arrival process for a hospital. Arrivals happen according to a stochastic process. I want it to be possible to specify whether an arrival
event is regarding an already existing customer
(in this case, I should give it as an argument) or that it is going to be a NEW customer
, in which case my arrival
constructor should create a new instance of customer.
class A:
def __init__(self, b=None):
if b is None:
self.b = B()
else:
self.b = b