In Python 3 you can do this without any decorators.
The following works and produces the same output:

class AA:
  def greet(A_instance):
     print("Hello", A_instance.name)

class BB:
  def greet(A_instance):
    print("Hi", A_instance.name)

class A:
  def __init__(self, state, name):
    self.state = state
    self.name = name
  def greet(self):
    self.state.greet(self)
  def switchAA(self):
    self.state = AA
  def switchBB(self):
    self.state = BB

if __name__ == "__main__":
  obj = A(AA, "alperen")
  obj.greet()
  obj.switchBB()
  obj.greet()

--
Greg
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/GL5ULTVXNAT5PWL5YMBH4LGQMIXJHMMQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to