没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Thinking
in
Python
Design Patterns and
Problem-Solving
Techniques
Bruce Eckel
President, MindView, Inc.
Please note that this document is in its initial form, and much remains to
be done.
Contents
Preface 5
Introduction 7
The Y2K syndrome..............8
Context and composition....9
A quick course in Python for programmers 11
Python overview.................11
Built-in containers........................12
Functions ......................................13
Strings ...........................................14
Classes...........................................16
The pattern concept 21
What is a pattern? ............. 21
Pattern taxonomy..............23
Design Structures..............24
Design principles...............25
The Singleton.....................27
Classifying patterns...........32
The development challenge33
Exercises............................34
2: Unit Testing 34
Write tests first..................36
Simple Python testing.......37
A very simple framework..38
Writing tests......................39
White-box & black-box tests42
Running tests.....................44
Automatically executing tests47
Exercises............................47
3: Building application frameworks 47
Template method ..............48
Exercises............................49
4:Fronting for an implementation 49
Proxy..................................50
State...................................52
StateMachine.....................54
Table-Driven State Machine61
The State class..............................63
Conditions for transition..............63
Transition actions.........................64
The table.......................................64
The basic machine........................65
Simple vending machine..............65
Testing the machine.....................70
Tools...................................70
Exercises............................70
X: Decorators: dynamic type selection 72
Basic decorator structure..73
A coffee example................73
Class for each combination73
The decorator approach....76
Compromise ......................79
Other considerations.........82
Exercises............................82
Y: Iterators: decoupling algorithms from containers 83
Type-safe iterators.............84
5: Factories: encapsulating object creation 85
Simple Factory method.....86
Polymorphic factories ...... 88
Abstract factories.............. 90
Exercises............................93
6: Function objects 94
Command: choosing the operation at run-time 94
Strategy: choosing the algorithm at run-time 96
Chain of responsibility ......97
Exercises.......................... 101
7: Changing the interface 101
Adapter ............................ 101
Façade..............................103
Exercises..........................104
8: Table-driven code: configuration flexibility 105
Table-driven code using anonymous inner classes 105
10: Callbacks 107
Observer .......................... 107
Observing flowers ...................... 109
A visual example of observers 116
Exercises.......................... 122
11: Multiple dispatching 122
Visitor, a type of multiple dispatching 127
Exercises..........................128
12: Pattern refactoring 130
Simulating the trash recycler130
Improving the design...... 134
“Make more objects”...................135
A pattern for prototyping creation 137
Trash subclasses........................142
Parsing Trash from an external file143
Recycling with prototyping.........146
Abstracting usage............ 147
Multiple dispatching ........151
Implementing the double dispatch152
The Visitor pattern..........158
A Reflective Decorator ................161
More coupling? ...........................166
RTTI considered harmful?166
Summary .........................169
Exercises...........................171
13: Projects 171
Rats & Mazes....................171
Other maze resources..................176
XML Decorator................ 176
Preface
The material in this book began in conjunction with a
Java seminar that I have given for several years, a couple
of times with Larry O’Brien, then with Bill Venners. Bill
剩余176页未读,继续阅读
资源评论
- carlshen82013-05-31相当给李, 深入学习的好资料啊. 鼓励一下.
leehark
- 粉丝: 57
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功