python - Sharing controller between views -
i have frame holds 2 views. want use common controller both of them not instantiate 2 controllers. how achieve this? singleton? send controller argument?
note, controller hold temporary data (bad idea?) sent away on command. that's why want 1 controller object. don't shy suggest other design ideas.
first view
class viewalpha def __init_(self, parent): self.controller = controller() def on_click(self, event): self.controller.do_this(event.data) second view
class viewbeta def __init_(self, parent): self.controller = controller() def on_click(self, event): self.controller.do_this(event.data) controller
class controller def __init_(self): self.client = client() def do_this(self, data): self.client.store(data)
passing things arguments, in code, common solution problems this. if need do_this -method, can pass method:
beta = viewbeta(controller.do_this)
Comments
Post a Comment