没有合适的资源?快使用搜索试试~ 我知道了~
首页Design Patterns:Elements of Reusable Object-Oriented Software
资源详情
资源评论
资源推荐

ptg

ptg
C r e a t i o n a l
P a t t e r n s
A b s t r a c t F a c t o r y ( 8 7 ) P r o v i d e
a n
interface
f o r
c r e a t i n g
families
o f
r e l a t e d
o r
d e p e n d e n t
o b j e c t s
without s pe c if y in g t h e i r c o n c r e t e c l a s s e s .
Builder
( 9 7 ) S e p a r a t e
t h e
c o n s t r u c t i o n
o f a
c o m p l e x o b j e c t
from
i t s
r e p r e s e n t a t i o n
s o
that
t h e
s a m e c o n s t r u c t i o n p r o c e s s
c a n
c r e a t e
different
r e p r e s e n t a t i o n s .
F a c t o r y
Met h od ( 1 0 7 )
D e f i n e
a n
i n t e r f a c e
f o r
c r e a t i n g
a n
o b j e c t ,
b u t l e t
s u b c l a s s e s
d e -
c i d e w h i c h c l a s s
t o
ins t an t i ate . F a c t o r y M e t h o d l e t s
a
c l a s s
defer
i n s t a n ti a t i o n
t o
s u b c l a s s e s .
P r o t o t y p e ( 1 1 7 )
S p e c i f y
t h e
k i n d s
o f
o b j e c t s
t o
c r e a t e u s i n g
a
p r o t o ty p i c a l i n s t a n c e ,
a n d
c r e a t e
n e w
o b j e c t s
b y
c o p y i n g t h i s p r oto t y pe.
S i n g l e t o n
( 1 2 7 ) E n s u r e
a
c l a s s o n l y
h a s o n e
i n s t a n c e ,
a n d
p r o v i d e
a
g l o b a l p o i n t
o f
a c c e s s
to it.
S t r u c t u r a l
P a t t e r n s
Adapter ( 1 3 9 ) C o n v e r t
t h e
interface
o f a
c l a s s i n t o another i n t e r f a c e c l i e n t s e x p e c t .
Adapter
l e t s
c l a s s e s
work t o g e t h e r that
c o u l d n ' t
o t h e r w i s e b e c a u s e
o f
i n c o m p a t -
i b l e i n t e r f a c e s .
B r i d g e ( 1 5 1 ) D e c o u p l e
a n
a b s t r a c t i o n
from
i t s
i mp l em e nt a ti on
s o
that
t h e t w o c a n
vary
i n d e p e n d e n t l y .
C o m p o s i t e
( 1 6 3 ) C o m p o s e o b j e c t s i n t o t r e e s t r u c t u r e s
t o
r e p r e s e n t par t -w h o le hierar-
c h i e s . C o m p o s i t e l e t s c l i e n t s treat individual o b j e c t s
a n d
c o m p o s i t i o n s
o f
o b j e c t s
uniformly.
D e c o r a t o r ( 1 7 5 ) Attach a d d i t i o n a l r e s p o n s i b i l i t i e s
t o a n
o b j e c t
d y n a m i c a l l y . D e c o r a t o r s
pro vi de
a
fl e x i b l e
alternative
to
s u b c l a s s i n g
for
e xtend ing
functionality.
F a c a d e
( 1 8 5 ) P r o v i d e
a
unified
i n t e r f a c e
t o a s e t o f
interfaces
i n a
s u b s y s t e m . F a c a d e
defines
a
h i g h e r - l e v e l i n t e r f a c e that makes
th e
s u b s y s t e m e a s i e r
to
u s e .
F l y w e i g h t ( 1 9 5 )
U s e
s h a r i n g
t o
s u p p o r t l a r g e num be rs
o f
f i n e - g r a i n e d o b j e c t s
effi-
c i e n t l y .
P r o x y
( 2 0 7 ) P r o v i d e
a
s urr o gat e
o r
p l a c e h o l d e r
f o r
a n o t h e r o b j e c t
t o
c o n t r o l a c c e s s
t o
i t .

ptg
B e h a v i o r a l P a t t e r n s
Chain
o f
Responsibility ( 2 2 3 )
A v o i d
coupling
t h e
s e nd er
o f a
req ue st
to i ts
r e c e i v e r
b y
g i v i n g more than
o n e
o b j e c t
a
c h a n c e
t o
h a n d l e
t h e
r e q u e s t . C h a i n
t h e
r e c e i v i n g
o b j e c t s
and
p a s s
the
re quest along
the
chain until
an
o b j ec t
handles
it.
C o m m a n d ( 2 3 3 ) E n c a p s u l a t e
a
r e q u e s t
a s a n
o b j e c t , t h e r e b y l e t t i n g
y o u
pa r a m e te r -
ize
c l ients with
different
r e q u e s t s , queue
or log
r e q u e s t s ,
and
support undoable
operations.
Interpreter ( 2 4 3 ) Given
a
language,
define
a
r ep re se nt ion
for its
grammar along with
an
interpreter that u s e s
the
representation
to
interpret s e n t e n c e s
in the
lan guag e.
Iterator
( 2 5 7 ) P r o v i d e
a way to
a c c e s s
the
elements
of an
aggregate
o b je c t
sequentially
without e x p o s i n g
i t s
u n d e r l y i n g r e p r e s e n t a t i o n .
Mediator ( 2 7 3 )
D e f i n e
a n
o b j e c t
that encapsulates
h o w a s e t o f
o b j e c t s interact.
Me-
dia t or p r o m o t e s
l o o s e
c o u p l i n g
b y
k e e p i n g o b j e c t s
from
r e fe r ri n g
t o
e a c h o t h e r
explicitly,
and it
l e t s
you
vary t he ir interaction independently.
Memento
( 2 8 3 ) Without violating encapsulation, capture
and
externalize
an
ob j ec t' s
internal
state
so
that
the
ob j e ct
can be
r es to r ed
to
this state later.
Observer ( 2 9 3 )
Define
a
one-to-many d e pe n d en c y between obj e c t s
s o
that when
on e
o b j e c t
c h a n g e s state,
all its
dependents
are
notified
and
updated automatically.
S t at e ( 3 0 5 ) Allow
an
obje ct
to
alter
its
behavior when
its
internal state chang e s .
The
o b j e c t
w i l l a p pe a r
t o
c h a n g e
i t s
c l a s s .
Strategy ( 3 1 5 )
Define
a
family
of
algorithms, encapsulate e a c h o n e ,
and
make them
i n t e r c h a n g e a b l e . S t r a t e g y l e t s
th e
a l g or i th m vary in d e p e n d e n t l y
from
c l i e n t s that
use it .
T e m p l a t e M e t h od ( 3 2 5 )
D e f i n e
t h e
s k e l e t o n
o f a n
a l g o r i t h m
i n a n
o p e r a t i o n ,
d ef e rr ing
s o m e st eps
to
s u b c l a s s e s . Template Method l e t s s u b c l a s s e s
redefine
certain steps
of
an
algorithm without chan ging
the
algorithm's structure.
Visitor
( 3 3 1 ) Represent
a n
operation
t o b e
performed
o n the
elements
o f a n
ob je ct
structure.
V i s i t o r l e t s
yo u
define
a n ew
operation without changing
t he
c l a s s e s
of
t h e
elements
on
which
it
operates.

ptg
This page intentionally left blank

ptg
D e s i g n
Patterns
剩余416页未读,继续阅读

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0