没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Thinking
in
Patterns
Problem-Solving Techniques
using Java
Bruce Eckel
President, MindView, Inc.
Notice:
Thinking in Patterns by Bruce Eckel
Revision 0.9, 5-20-2003 (This version contains the material that will
be used in the Crested Butte seminar; see
http://www.mindview.net/Seminars/ThinkingInPatterns/)
Please note this document is under development and incomplete.
Updates to this document can be found at http://www.Mindview.net
Best viewed with Mozilla! (free at www.Mozilla.org) (Even though
this document was created with MS Word, IE6 garbles lines with
superscripts on them. Mozilla seems to do a much better job).
___________________________________________
Note: This document requires the installation of the fonts Georgia, Verdana and Andale
Mono (code font) for proper viewing. These can be found at:
http://sourceforge.net/project/showfiles.php?group_id=34153&release_id=105355
Modifications in Revision 0.9:
Prose has still had little/no work. My current goal is to get the structure and
examples worked out so that the seminar works well. Once it has been proven in the
seminars, then I will spend time on the prose.
Added proxy:PoolManager.java to make a more generic/customizeable Pool
Manager, and modified proxy:ConnectionPoolProxyDemo.java accordingly [[ Still
need to decide what to return when you run out of objects in the pool ]]
Changed PoolManager.java to use an ArrayList (and thus does not require a fixed
size at initialization)
Added KissingPrincess.java to State description, as a motivational example for the
pattern
Added a simple Flyweight example
Simplified the enumeration in PaperScissorsRock.java
Modifications in Revision 0.8:
Changed Bridge example to improve clarity.
Removed superscripts for better viewing with IE (see note above)
Modifications in Revision 0.7:
NOTE primary changes have been made to structure of book and code
examples, but not to prose. Prose can be considered to be mostly a mess
in this revision.
Complete reorganization under headings that attempt to describe the problems you
are trying to solve with a pattern.
Addition of placeholders for the remainder of the GoF patterns
Addition of ―Simplifying Idioms‖ section and examples
Addition of Builder section and examples
Removed unit-testing chapter; replaced with reference to ―new‖ JUnit (which uses
reflection)
(4-30-2003) Added Ant build.xml files, and support files from TIJ necessary to do a
full standalone build. You should be able to type ―ant‖ from the code root directory
and get a successful build.
Dramatically simplified chainofresponsibility:FindMinima.java
Added object pool/connection pool examples
Refactored small things in many examples
Some exercises may have been left behind when patterns were moved.
For simplicity, saved from Word into a single HTML document, using ―filtered‖
version to remove Office stuff. Seems to work pretty well; checked it with both IE and
Mozilla (actually seems to work better on Mozilla than on IE!).
TODO:
Reconfigure for new backtalk system
Replace references to TIJ2 with TIJ3
Contents
Preface 9
Introduction 10
The Y2K syndrome .....................................................................................................................10
Context and composition ........................................................................................................... 11
A word about checked exceptions .............................................................................................. 11
The pattern concept 13
What is a pattern? ...................................................................................................................... 13
Pattern taxonomy ....................................................................................................................... 14
Design principles ........................................................................................................................ 14
Classifying patterns .................................................................................................................... 15
The development challenge ........................................................................................................ 16
Unit testing ................................................................................................................................. 17
Location of test code ............................................................................................................... 17
Simplifying Idioms 18
Messenger .................................................................................................................................. 18
Collecting Parameter .................................................................................................................. 19
Object quantity 21
Singleton .................................................................................................................................... 21
Exercises ................................................................................................................................ 22
Object pool ................................................................................................................................ 23
Exercises ................................................................................................................................ 25
Object decoupling 26
Proxy: fronting for another object ............................................................................................ 26
The PoolManager using Proxy ............................................................................................... 27
Dynamic Proxies .................................................................................................................... 30
State: changing object behavior ................................................................................................ 32
Iterators: decoupling algorithms from containers .................................................................... 36
Type-safe iterators ................................................................................................................. 37
Exercises .................................................................................................................................... 38
Factoring commonality 39
Strategy: choosing the algorithm at run-time ........................................................................... 39
Policy: generalized strategy ....................................................................................................... 40
Template method ....................................................................................................................... 41
Exercises ................................................................................................................................ 42
Encapsulating creation 43
Simple Factory method ............................................................................................................. 43
Polymorphic factories ............................................................................................................... 45
Abstract factories ...................................................................................................................... 47
Exercises .................................................................................................................................... 49
Specialized creation 51
Prototype .................................................................................................................................... 51
Builder ........................................................................................................................................ 51
Exercises .................................................................................................................................... 54
Too many 55
Flyweight: too many objects...................................................................................................... 55
Decorator: too many classes ...................................................................................................... 57
Basic decorator structure ....................................................................................................... 57
A coffee example ..................................................................................................................... 57
Class for each combination.................................................................................................... 58
The decorator approach ........................................................................................................ 60
Compromise .......................................................................................................................... 64
Other considerations ............................................................................................................. 67
Exercises ................................................................................................................................ 68
Connecting different types 69
Adapter ...................................................................................................................................... 69
Bridge ......................................................................................................................................... 71
Exercises .................................................................................................................................... 76
Flexible structure 77
Composite................................................................................................................................... 77
System decoupling 79
Observer .................................................................................................................................... 79
剩余194页未读,继续阅读
wuyaowen2000
- 粉丝: 11
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页