没有合适的资源?快使用搜索试试~ 我知道了~
Head_First_Design_Patterns.pdf (英文版)
2星 需积分: 9 133 下载量 149 浏览量
2008-11-29
15:36:52
上传
评论
收藏 10.98MB PDF 举报
温馨提示
试读
176页
Head_First_Design_Patterns.pdf (英文版)
资源推荐
资源详情
资源评论
x
Intro
Your brain on Design Patterns. Here you are trying to learn something, while
here your brain is doing you a favor by making sure the learning doesn’t stick. Your brain’s
thinking, “Better leave room for more important things, like which wild animals to avoid and
whether naked snowboarding is a bad idea.” So how do you trick your brain into thinking
that your life depends on knowing Design Patterns?
Who is this book for? xxvi
We know what your brain is thinking xxvii
Metacognition xxix
Bend your brain into submission xxxi
Technical reviewers xxxiv
Acknowledgements xxxv
Table of Contents (summary)
Intro xxv
1 Welcome to Design Patterns: an introduction 1
2 Keeping your Objects in the know: the Observer Pattern 37
3 Decorating Objects: the Decorator Pattern 79
4 Baking with OO goodness: the Factory Pattern 109
5 One of a Kind Objects: the Singleton Pattern 169
6 Encapsulating Invocation: the Command Pattern 191
7 Being Adaptive: the Adapter and Facade Patterns 235
8 Encapsulating Algorithms: theTemplate Method Pattern 275
9 Well-managed Collections: the Iterator and Composite Patterns 315
10 The State of Things: the State Pattern 385
11 Controlling Object Access: the Proxy Pattern 429
12 Patterns of Patterns: Compound Patterns 499
13 Patterns in the Real World: Better Living with Patterns 577
14 Appendix: Leftover Patterns 611
Table of Contents (the real thing)
table of contents
xi
1
Welcome to Design Patterns
Someone has already solved your problems. In this chapter,
you’ll learn why (and how) you can exploit the wisdom and lessons learned by
other developers who’ve been down the same design problem road and survived
the trip. Before we’re done, we’ll look at the use and benefits of design patterns,
look at some key OO design principles, and walk through an example of how one
pattern works. The best way to use patterns is to
load your brain with them and
then recognize places in your designs and existing applications where you can
apply them. Instead of code reuse, with patterns you get experience reuse.
intro to Design Patterns
Your BRAIN
Your Code, now new
and improved with
design patterns!
A Bunch of Patterns
swim()
display
()
performQuack()
performFly()
setFlyBehavior()
setQuackBehavior()
// OTHER duck-like methods...
Duck
FlyBehavior flyBehavior;
QuackBehavior quackBehavior;
<<interface>>
FlyBehavior
fly()
fly() {
// implements duck flying
}
FlyWithWings
fly() {
// do nothing - can’t fly!
}
FlyNoWay
<<interface>>
QuackBehavior
quack()
quack) {
// implements duck quacking
}
Quack
quack() {
// rubber duckie squeak
}
Squeak
quack() {
// do nothing - can’t quack!
}
MuteQuack
display() {
// looks like a decoy duck }
Decoy Duck
display() {
// looks like a mallard }
Mallard Duck
display() {
// looks like a redhead }
Redhead Duck
display() {
// looks like a rubberduck }
Rubber Duck
Encapsulated fly behavior
Encapsulated quack behavior
Client
V
iew
Controller
Model
Request
MVC
S
u
b
j
e
c
t
O
b
j
e
c
t
8
int
D
o
g
O
b
j
e
c
t
M
o
u
s
e
O
b
j
e
c
t
C
a
t
O
b
j
e
c
t
D
u
c
k
O
b
j
e
c
t
Observers
8
8
8
8
Automatic update/notification
Object that
holds state
Dependent Objects
OBSERVER
Remember, knowing
concepts like abstraction,
inheritance, and polymorphism do
not make you a good object oriented
designer. A design guru thinks
about how to create flexible
designs that are maintainable
and that can cope with
change.
The SimUDuck app 2
Joe thinks about inheritance...
5
How about an interfac
e? 6
The one constant in software development
8
Separating what changes from what stays the same 1
0
Designing the Duck Behaviors 11
Testing the Duck code 1
8
Setting behavior dynamically 2
0
The Big Picture on encapsulated behaviors 2
2
HAS-A can be better than IS-A 23
The Strategy Pattern 24
The power of a shared pattern vocabulary 2
8
How do I use Design Patterns? 2
9
Tools for your Design Toolbox 3
2
Exercise Solutions
34
xii
The Weather Monitoring application 39
Meet the Observer Pattern 44
Publishers + Subscribers = Observer Pattern 4
5
Five minute drama
: a subject for observation 48
The Observer Pattern defined 51
The power of Loose Coupling 5
3
Designing the Weather Station 56
Implementing the Weather Station 5
7
Using Java’s built-in Observer Pattern 64
The dark side of java.util.Observable 7
1
Tools for your Design Toolbox 7
4
Exercise Solutions 78
2
Keeping your Objects in the Know
Don’t miss out when something interesting happens!
We’ve got a pattern that keeps your objects in the know when something they
might care about happens. Objects can even decide at runtime whether they
want to be kept informed. The Observer Pattern is one of the most heavily used
patterns in the JDK, and it’s incredibly useful. Before we’re done, we’ll also look
at one to many relationships and loose coupling (yeah, that’s right, we said
coupling). With Observer, you’ll be the life of the Patterns Party.
the Observer Pattern
S
u
b
j
e
c
t
O
b
j
e
c
t
8
int
D
o
g
O
b
j
e
c
t
M
o
u
s
e
O
b
j
e
c
t
C
a
t
O
b
j
e
c
t
D
u
c
k
O
b
j
e
c
t
Observers
8
8
8
8
ONE TO MANY RELATIONSHIP
Automatic update/notification
Object that
holds state
Dependent Objects
Abstraction
Encapsulation
Polymorphism
Inheritence
OO Basics
Encapsulate what varies
Favor Composition over inheri
-
tance
Program to Interfaces, not
implementations
Strive for loosely coupled
designs between objects that
interact
OO Principles
table of contents
xiii
3
Decorating Objects
Just call this chapter “Design Eye for the Inheritance
Guy.”
We’ll re-examine the typical overuse of inheritance and you’ll learn how
to decorate your classes at runtime using a form of object composition. Why?
Once you know the techniques of decorating, you’ll be able to give your (or
someone else’s) objects new responsibilities
without making any code changes
to the underlying classes.
the Decorator Pattern
I used to think real men
subclassed everything. That was until
I learned the power of extension
at runtime, rather than at compile
time. Now look at me!
Welcome to Starbuzz Coffee 80
The Open-Closed Principle 8
6
Meet the Decorator Pattern 88
Constructing a Drink Order with Decorators 8
9
The Decorator Pattern De
fined 91
Decorating our Beverages 9
2
Writing the Starbuzz code 95
Real World Decorators: Java I/O 10
0
Writing your own Java I/O Decorator 10
2
Tools for your Design Toolbox 10
5
Exercise Solutions 1
06
xiv
4
Baking with OO Goodness
Get ready to cook some loosely coupled OO designs.
There is more to making objects than just using the new operator. You’ll learn
that instantiation is an activity that shouldn’t always be done in public and can
often lead to coupling problems. And you don’t want that, do you? Find out how
Factory Patterns can help save you from embarrasing dependencies.
the Factory Pattern
<<interface>>
Clams
<<interface>>
Cheese
<<interface>>
Sauce
<<interface>>
Dough
createPizza()
NYPizzaStore
ThinCrustDough
MarinaraSauce
ReggianoCheese
FrozenClams
ThickCrustDough
PlumTomatoSauce
Mozzarella Cheese
FreshClams
Each factory produces a different
implementation for the family of products.
The abstract PizzaIngredientFactory
is the interface that defines how to
make a family of related products
- everything we need to make a pizza.
The clients of the Abstract
Factory are the two
instances of our PizzaStore,
NYPizzaStore and
ChicagoStylePizzaSore.
The job of the concrete
pizza factories is to
make pizza ingredients.
Each factory knows
how to create the right
objects for their region.
createDough()
createSauce()
createCheese()
createVeggies()
createPepperoni()
createClam()
<<interface>>
PizzaIngredientFactory
createDough()
createSauce()
createCheese()
createVeggies()
createPepperoni()
createClam()
NYPizzaIngredientFactory
createDough()
createSauce()
createCheese()
createVeggies()
createPepperoni()
createClam()
ChicagoPizzaIngredientFactory
table of contents
When you see “new”, think “concrete” 110
Objectville Pizza 11
2
Encapsulating object creation 11
4
Building a simple pizza factory 115
The Simple Factory
defined 117
A Framework for the pizza store 12
0
Allowing the subclasses to decide 121
Let’s make a PizzaStore 12
3
Declaring a factory method 12
5
Meet the Factory Method Pattern 131
Parallel class hierarchies 132
Factory
Method Pattern defined 134
A very dependent PizzaStore 13
7
Looking at object dependencies 13
8
The Dependency Inversion Principle 13
9
Meanwhile, back at the PizzaStore... 14
4
Families of ingredients... 145
Building our ingredient factories 14
6
Looking at the Abstract Factory 15
3
Behind the scenes 15
4
Abstract Factory Pattern defined 156
Factory Method and Abstract Factory compared 16
0
Tools for your Design Toolbox 16
2
Exercise Solutions 16
4
剩余175页未读,继续阅读
资源评论
- kingscl2011-10-28内容非常少,而且是影印版,不清晰
- chanhit2012-04-06是啊 不是很清楚 好像这书没有清晰版的
andylin02
- 粉丝: 792
- 资源: 68
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功