fork download
  1. class Application:
  2.  
  3. def __init__(self):
  4. self.instanceA = ClassA(self)
  5. self.instanceB = ClassB(self)
  6.  
  7. def run(self):
  8. self.instanceA.send_hello()
  9. self.instanceB.send_hello()
  10.  
  11. class ClassA:
  12. def __init__(self, app):
  13. self.app = app
  14.  
  15. def hello(self, sender):
  16. print('A: Hello from {}'.format(sender))
  17.  
  18. def send_hello(self):
  19. self.app.instanceB.hello("A")
  20.  
  21. class ClassB:
  22. def __init__(self, app):
  23. self.app = app
  24.  
  25. def hello(self, sender):
  26. print('B: Hello from {}'.format(sender))
  27.  
  28. def send_hello(self):
  29. self.app.instanceA.hello("B")
  30.  
  31. app = Application()
  32. app.run()
Success #stdin #stdout 0.01s 9992KB
stdin
Standard input is empty
stdout
B: Hello from A
A: Hello from B