Suppose I have the following example:
import uuid
class A:
def __init__(self):
self.id = uuid.uuid4().hex
class B(A):
def __init__(self):
super().__init__()
self.print_id()
def print_id(self):
print(self.id)
class C(A):
def __init__(self):
super().__init__()
self.print_id()
def print_id(self):
print(self.id)
We have class B and C that are inheriting A. Once B or C are instantiated, they will print the unique ID created in the super class. The issue I am running into here is that each time B or C is instantiated, there is a brand new id created for class A. I would like to print/use the SAME ID for both class B and C. In other words, I only want to have one instance of class A to be used for B and C. Without involving any sort of logic surrounding singletons, how can I achieve this? How can class C know that class B has already initialized class A, therefore an ID already exists? I am attempting to create a base class that is initialized only once, and that ID is inherited by all the sub classes. Any help here would be appreciated.