Delegates in python

前端 未结 2 1670
攒了一身酷
攒了一身酷 2021-02-01 20:45

I\'ve implemented this short example to try to demonstrate a simple delegation pattern. My question is. Does this look like I\'ve understood delegation right?

cl         


        
相关标签:
2条回答
  • 2021-02-01 21:01

    That's the basic concept, yes - passing on some incoming request to another object to take care of.

    0 讨论(0)
  • 2021-02-01 21:15

    One Python tip: you don't need to say:

    func = getattr(self.handler, 'Handle')
    func(event)
    

    just say:

    self.handler.Handle(event)
    

    I'm not sure what you are doing with your Handler class, it isn't used in your example.

    And in Python, methods with upper-case names are very very unusual, usually a result of porting some existing API with names like that.

    0 讨论(0)
提交回复
热议问题