-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChainOfResponsibility.py
More file actions
58 lines (46 loc) · 1.25 KB
/
ChainOfResponsibility.py
File metadata and controls
58 lines (46 loc) · 1.25 KB
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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Time : 2022/08/26 15:26:00
# @Author : Gary
# @Email : None
from abc import ABCMeta, abstractmethod
class Handler(metaclass=ABCMeta):
# 抽象的处理者
@abstractmethod
def handle_leave(self, day):
pass
class GeneralManager(Handler):
# 具体的处理者
def handle_leave(self, day):
if day <= 30:
print('总经理准假%d' % day)
else:
print('可以辞职了!')
class DepartmentManager(Handler):
# 具体的处理者
def __init__(self):
self.next = GeneralManager()
def handle_leave(self, day):
if day <= 7:
print('部门经理准假%d' % day)
else:
print('部门经理职权不足')
self.next.handle_leave(day)
class ProjectDirector(Handler):
# 具体的处理者
def __init__(self):
self.next = DepartmentManager()
def handle_leave(self, day):
if day <= 3:
print('项目主管准假%d' % day)
else:
print('项目主管职权不足')
self.next.handle_leave(day)
day = 20
p = ProjectDirector()
p.handle_leave(day)
"""
项目主管职权不足
部门经理职权不足
总经理准假20
"""