forked from faif/python-patterns
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchaining_method.py
More file actions
Latest commit
33 lines (23 loc) · 643 Bytes
/
Copy pathchaining_method.py
File metadata and controls
33 lines (23 loc) · 643 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
classPerson(object):
def__init__(self, name, action):
self.name=name
self.action=action
defdo_action(self):
print(self.name, self.action.name, end=' ')
returnself.action
classAction(object):
def__init__(self, name):
self.name=name
defamount(self, val):
print(val, end=' ')
returnself
defstop(self):
print('then stop')
if__name__=='__main__':
move=Action('move')
person=Person('Jack', move)
person.do_action().amount('5m').stop()
### OUTPUT ###
# Jack move 5m then stop