Skip to content

Commit b655bf0

Browse files
committed
Merge branch 'duythinht-master'
2 parents a6dbd6f + f4395ad commit b655bf0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ Current Patterns:
3838
| [strategy](strategy.py) | selectable operations over the same data |
3939
| [template](template.py) | an object imposes a structure but takes pluggable components |
4040
| [visitor](visitor.py) | invoke a callback for all items of a collection |
41+
| [chaining_method](chaining_method.py) | continue callback next object method |

chaining_method.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
class Person(object):
5+
6+
def __init__(self, name, action):
7+
self.name = name
8+
self.action = action
9+
10+
def do_action(self):
11+
print(self.name, self.action.name, end=' ')
12+
return self.action
13+
14+
class Action(object):
15+
16+
def __init__(self, name):
17+
self.name = name
18+
19+
def amount(self, val):
20+
print(val, end=' ')
21+
return self
22+
23+
def stop(self):
24+
print('then stop')
25+
26+
if __name__ == '__main__':
27+
28+
move = Action('move')
29+
person = Person('Jack', move)
30+
person.do_action().amount('5m').stop()
31+
32+
### OUTPUT ###
33+
# Jack move 5m then stop

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy