I have following code block.
class Starter():
def __init__(self, reference):
self.reference = reference
def change_ref(self):
print("Got :", self.reference)
self.reference = 1
print("Now :", self.reference)
class Stopper():
def __init__(self, reference):
self.reference = reference
def change_ref(self):
print("Got :", self.reference)
self.reference = 2
print("Now :", self.reference)
class Controller():
def __init__(self):
self.main_reference = 0
self.starter = Starter(self.main_reference)
self.stopper = Stopper(self.main_reference)
controller = Controller()
controller.starter.change_ref()
controller.stopper.change_ref()
and it outputs the following :
Got : 0
Now : 1
Got : 0
Now : 2
I want the starter and stopper class to modify and reach to same object. So the output I am looking is the following :
Got : 0
Now : 1
Got : 1
Now : 2
What is the best way to do this with using three different classes? Rather than array usage I am curious if we can take advantage of classes. If possible I can also use nested classes. My only constraint is that Starter
and Stopper
classes must be separated from each other since in my project I am using them as QThread
subclasses. Which leads them to override their run method in a
different way.