File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff 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 |
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments