1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
class Request(object): def __init__(self): self.requestType = '' self.requestContent = '' self.number = 0
class Manager(object): def __init__(self, name): self.name = name self.superior = None def setSuperior(self, superior): self.superior = superior def handleRequest(self, request): raise NotImplementedError()
class CommonManager(Manager): def __init__(self, name): super(CommonManager, self).__init__(name) def handleRequest(self, request): if request.requestType==u'请假' and request.number<=2: print u'{} {} 数量:{} 被批准'.format(self.name, request.requestContent, request.number) else: if self.superior: self.superior.handleRequest(request)
class Majordomo(Manager): def __init__(self, name): super(Majordomo, self).__init__(name) def handleRequest(self, request): if request.requestType==u'请假' and request.number<=5: print u'{} {} 数量:{} 被批准'.format(self.name, request.requestContent, request.number) else: if self.superior: self.superior.handleRequest(request)
class GeneralManager(Manager): def __init__(self, name): super(GeneralManager, self).__init__(name) def handleRequest(self, request): if request.requestType==u'请假': print u'{} {} 数量:{} 被批准'.format(self.name, request.requestContent, request.number)
if __name__ == '__main__': jinli = CommonManager(u"经理") zongjian = Majordomo(u"总监") zhongjingli = GeneralManager(u"总经理")
jinli.setSuperior(zongjian) zongjian.setSuperior(zhongjingli)
request = Request()
request.requestType=u"请假" request.requestContent=u"李俊宏请假" request.number=1 jinli.handleRequest(request)
request.requestType=u"请假" request.requestContent=u"李俊宏请假" request.number=4 jinli.handleRequest(request)
request.requestType=u"请假" request.requestContent=u"李俊宏请假" request.number=10 jinli.handleRequest(request)
|