Delegates in python

前端 未结 2 1671
攒了一身酷
攒了一身酷 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: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.

提交回复
热议问题