FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-patterns/chain.py at master · Casperito/python-patterns · GitHub
Casperito
/
python-patterns
Public
forked from
faif/python-patterns
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-patterns
/
chain.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (34 loc) · 1.17 KB
Breadcrumbs
python-patterns
/
chain.py
Copy path
File metadata and controls
48 lines (34 loc) · 1.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# http://www.testingperspective.com/wiki/doku.php/collaboration/chetan/designpatternsinpython/chain-of-responsibilitypattern
class
Handler
:
def
successor
(
self
,
successor
):
self
.
successor
=
successor
class
ConcreteHandler1
(
Handler
):
def
handle
(
self
,
request
):
if
request
>
0
and
request
<=
10
:
print
(
"in handler1"
)
else
:
self
.
successor
.
handle
(
request
)
class
ConcreteHandler2
(
Handler
):
def
handle
(
self
,
request
):
if
request
>
10
and
request
<=
20
:
print
(
"in handler2"
)
else
:
self
.
successor
.
handle
(
request
)
class
ConcreteHandler3
(
Handler
):
def
handle
(
self
,
request
):
if
request
>
20
and
request
<=
30
:
print
(
"in handler3"
)
else
:
print
(
'end of chain, no handler for {}'
.
format
(
request
))
class
Client
:
def
__init__
(
self
):
h1
=
ConcreteHandler1
()
h2
=
ConcreteHandler2
()
h3
=
ConcreteHandler3
()
h1
.
successor
(
h2
)
h2
.
successor
(
h3
)
requests
=
[
2
,
5
,
14
,
22
,
18
,
3
,
35
,
27
,
20
]
for
request
in
requests
:
h1
.
handle
(
request
)
if
__name__
==
"__main__"
:
client
=
Client
()
Back
|
FazBrowse Home
|
New Git URL