what would be a good way to ensure that only a unique instance is created when class object is initialized, please be specific in your answers.
for example for the following class I want to make sure when I create an StateMachineSystems
instance with 'TEST'
any latter created objects (y
in this case) points to x
created previously.
class StateMachineSystems:
def __init__(self,system_name):
self.system_name = system_name
def set_sequence_number(self,sequnce_number):
self.sequnce_number = sequnce_number
def get_sequence_number(self):
return self.sequnce_number
def get_system_name(self):
return self.system_name
x = StateMachineSystems('TEST')
y = StateMachineSystems('TEST')
if x==y:
print("single instance")
....
single instance