Thinking.In.Python

VIP免费
2025-02-27 0 0 831.45KB 177 页 5.9玖币
侵权投诉
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
摘要:

ThinkinginPythonDesignPatternsandProblem-SolvingTechniquesBruceEckelPresident,MindView,Inc.Pleasenotethatthisdocumentisinitsinitialform,andmuchremainstobedone.ContentsPreface5Introduction7TheY2Ksyndrome..............8Contextandcomposition....9AquickcourseinPythonforprogrammers11Pythonoverview..........

展开>> 收起<<
Thinking.In.Python.pdf

共177页,预览5页

还剩页未读, 继续阅读

声明:本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。玖贝云文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知玖贝云文库,我们立即给予删除!
分类:计算机 价格:5.9玖币 属性:177 页 大小:831.45KB 格式:PDF 时间:2025-02-27

开通VIP享超值会员特权

  • 多端同步记录
  • 高速下载文档
  • 免费文档工具
  • 分享文档赚钱
  • 每日登录抽奖
  • 优质衍生服务
/ 177
客服
关注