ООПИС Конспект(слайды) лекций 2007
.pdf[$"
•Q$* $#
" ^$$`
•$# *!
"$ $^ `
•*$U ! ]$$
]
|
|
|||
class Decorator |
|
|
|
|
|
|
Component |
|
|
|
+ |
Operation() |
|
|
ConcreteComponent |
Decorator |
-component |
||
|
|
|
|
|
+ |
Operation() |
+ |
Operation() |
|
|
|
|
component->Operation() |
|
|
ConcreteDecoratorA |
|
ConcreteDecoratorB |
|
|
- |
addedState |
+ |
AddedBehavior() |
|
+ |
Operation() |
+ |
Operation() |
|
|
Decorator::Operation(); |
||
|
|
|
|
|
|
|
|
|
AddedBehavior(); |
V Q
•[$ $ $ $" *$!
$b$ $* ^
$* ! *$
[ " \$ $
_$
• Y$\ b * * #
[$"
•$!$] ! * * \
^ $\ ! *
$`
•]$" \ \ \
* * ] * * d * ^ `
•$ * Z #$ $"+ \ Q \ * * \ $! !$" ] Z #
class Iterator |
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
Aggregate |
|
|
|
Iterator |
||
|
|
+ CreateIterator() |
|
|
+ |
CurrentItem() |
||
|
|
|
|
|
|
|
+ |
First() |
|
|
|
|
|
|
|
+ |
IsDone() |
|
|
|
|
|
|
|
+ |
Next() |
|
|
|
|
|
|
|
|
|
|
ConcreteAggregate |
ConcreteIterator |
+ |
CreateIterator() |
|
|
return new |
|
|
ConcretIterator(this) |
|
V Q
•X$ $ \ ^$
W"+$ ^
! *
J
[$"
•$ $ $* #$ +$
!+$ $+$! `
•$! $$+$
`
•* Q ] "$\ #
$$Z " \ \$$
! `
•b $$*! \ "$
Q \$ $# h ] "$!
!$"$ $!+W Q$
" \$" ] #
$$!Q !+ \ W$ $
class Prototype |
|
|
|
|
|
|
Client |
|
Prototype |
|
|
|
-prototype |
|
|
|
|
+ |
Operation() |
+ |
Cl one() |
|
|
|
p = |
|
|
|
|
|
prototype->Clone() |
|
|
|
|
|
ConcretePrototype1 |
ConcretePrototype2 |
|||
|
+ |
Clone() |
|
+ |
Clone() |
|
|
return copy of |
|
|
return copy of |
|
|
self |
|
|
self |
[$"
V Q
•X$+ !+$]
^ #$! d ! [$" " !+
+ $$b \ ^
_$
•X ] " ^ !
$$
[$"
[$"
•$! !$!$!+ ^ * \$$ $ Q
Z #d$\ " $W
\$$`
•^ \ W$ $ $! ! "
d$ ] !$# \
i $"j$$[$"
^ "$d$\$$c$
$! ! ^$W #$" \ ] #
$" ] d] +Q " "
$W$! `
•$$!$+W$! ! ! ^ +$
b #$! ! # +$Q$[
$$ $\$! ! !] !
" Z #$ $\$# b ] "
! [ b !$ $$+ d$ $Q Q$
!QU " \
[$"
class Visitor
Visitor
+VisitConcreteEl ementA(ConcreteElementA)
+VisitConcreteEl ementB(ConcreteElementB)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConcreteVisitor1 |
|
|
|
ConcreteVisitor2 |
||||
+ |
VisitConcreteElementA(ConcreteElementA) |
|
|
+ |
VisitConcreteElementA(ConcreteElementA) |
||||
+ |
VisitConcreteElementB(ConcreteElementB) |
|
|
+ |
VisitConcreteElementB(ConcreteElementB) |
||||
|
|
|
|
|
|
|
|
|
|
ObjectStructure |
Element |
1..* |
Accept(Visitor) |
+ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConcreteElementA |
|
|
|
ConcreteElementB |
|||
+ Accept(Visitor) |
|
|
+ Accept(Visitor) |
||||
v->VisitConcreteElementA(this) |
|
|
v->VisitConcreteElementB(this) |
||||
|
|
|
|
|
|
|
|
k Q $#
V Q
• [ ] "
$* !Q + U$"
$ $" ^ Y ^ d
!Q Q ! $"
b # Q * +
_$
• X ^ +W # $
g
k Q $#
[$"
•$" * ^$ $*
" $Q$W #
Q $] "
# Q$`
•\ " $! $" \
^ ! ! `
•^$ $\ " $
] "$Q$
k Q $#
class Chain of Responsibility
-successor
|
Handler |
Client |
|
+ |
HandleRequest() |
|
|
|
|
|
|
|
|
|
|
|
|
ConcreteHandler1 |
|
|
ConcreteHandler2 |
||
+ HandleRequest() |
|
|
+ HandleRequest() |
||
|
|
|
|
|
|
|
|
|
|
|
|
k Q $#
[ !W$
•X$ $ $ $" ^
l "l * $
V$
•V * # Q $!$" ! * !Q
T W
V Q
•T ! ^$! !
$\ # Q$"d [
"
! "$d$^
_$
• Y ! !$ $^
T W
[$"
•!]$" \ + ^
Q$"d `
•\ Q
$ $! "d ^
T W
class Composite |
|
|
|
Component |
|
+ |
Add() : Component |
1..* |
Client |
GetChild() : Component |
|
+ |
|
|
+ |
Operation() |
|
+ |
Remove() : Component |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Leaf |
|
|
|
Composite |
|
|
|||
+ Operation() |
|
|
+ |
Add() : Component |
|
|
|||
|
|
|
|
||||||
|
|
|
|
+ |
GetChild() : Component |
|
-children |
||
|
|
|
|
+ |
Operation() |
|
|
||
|
|
|
|
|
forall g in children |
|
|
||
|
|
|
|
|
g.Operation(); |
|
|
||
|
|
|
|
+ |
Remove() : Component |
|
|
||
|
|
|
|
|
|
|
|
|
|
V + "
V Q
•X $ $" i * j ] ! ^ Q
$ $* ^$
$W * dW +$b
Q$+$
_$
•h ]$^ $W !* * ^
V + "
[$"
•* !$ $"$ \
$!* *$! b \$
^ + " d
$" " \ $`
•* Z * ^ !$
" !* $"
^ !] "`
•* ^ ] W " !* \
] # ! \ ^ \
f !*$\ Q ^
$ $ ] !$#
V + " |
|||||
class Observ er |
|
|
|
||
|
|
Subject |
|
|
|
+ |
Attach(Observer) |
|
|
Observer |
|
+ |
Detach(Observer) : Observer -observers |
|
|
||
|
|
|
|||
+ |
Notify() : Observer |
1..* |
+ |
Update() |
|
|
for all o in observers { |
||||
|
|
|
|
||
|
o->Update() |
|
|
|
|
|
} |
|
|
|
|
|
ConcreteSubj ect |
|
ConcreteObserv er |
||
|
|
|
|
||
|
- |
subjectState |
- |
observerState |
|
|
|
-subject |
|||
|
+ |
GetState() |
+ |
Update() |
|
|
|
return |
|||
|
|
|
|
observerState = |
|
|
|
subjectState |
|
|
|
|
|
|
|
subject->GetState() |
|
|
+ |
SetState() |
|
|
|
|
|
|
|
X U ] !
•!"#$!%&'
_$
•Y$ $ $ $* ^
V Q
•X$!$] * ^ *$Q ! " * * ]$$ $! *!
!Q "$ $
|
|
|
ON-0B17 |
||||
|
|
|
|
|
|
|
|
class Builder |
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
Director |
|
|
|
|
|
|
+ Construct() |
-builder |
Builder |
|
|
||
|
for all objects in |
|
|
|
|
|
|
|
structure { |
|
+ Buil dPart() |
|
|
||
|
builder->BuildPart() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConcreteBuilder |
Product |
+ |
Bui ldPart() |
+ |
GetResult() : void |
T
[
•V \$" ^ ! $
# U
! !Q
T
class Command |
|
|
|
|
|
|
Command |
Client |
Inv oker |
+ |
Execute() |
Receiv er
+ Action() |
-receiver |
ConcreteCommand
- state
+ Execute()
receiver->Action();
T
[ !W$
•[ lT l $ " ] ! ^ !+W ^
+W Z + "
*$ $^ lT l #
]$U " ! " ^
m$
[
•T$Q " ! Z # Z #$ $
\ #
Z #$ $ $ $#$
] "$ $ $b #
$ $# $ $]
"$n
m$
e U
•X " ! Q ! #$ $
$ $# d Z$# ^$Q +W # W # Z #$ $ $ $# ] " *
$" #$+$
m$d b U # ^$Q +W #
$!+ Q ! \$!]$ $
e !* \$ $
U m$# ^
$Q + lo$#Q #
l$Q W #
$ $
m$
class Facade
SubsystemClass1 |
SubsystemClass4 |
Facade |
SubsystemClass2 |
SubsystemClass5 |
SubsystemClass3 |
SubsystemClass6 |
SubsystemClass7 |
9(8237: q12>3B
class Factory Method |
|
Product |
Creator |
+ |
AnOperation() |
+ |
FactoryMethod() |
ConcreteProduct |
ConcreteCreator |
|
|
+ |
FactoryMethod() |
«instantiate» |
return new |
|
|
|
ConcreteProduct |
( [$ $
[
•V \$Q " ] ! ]$\
^
e
•[$ $!+$!W$Q$\
$U$^
$ $ $" " #$
+$ $!+W !$]
$" !$"U Q$^ d b *$\ \$
•"U!+ Q$"$ $^ ]$
•* * ! ^ ] "$"
"U Q$^$" !$ $
^$
( [$ $
e U
•Y " # ^ # ]
$" "$" \$\
Q ]$* $#
^ Q b #
$l[$ $l ^ Z #$ $
W"+ *$ $*! !Q "
U$ $d #$" *
lT #[$ $l ! Z #$
$$l[$ $l \$
!$ $
[ !W$
•r$ $! "U W * Q$b
$ $ $b$"
90:G1-/>2 |
|
|
class Flyw eight |
|
|
|
[ |
|
|
||
|
|
|
|
|
class Interpreter |
|
||
|
Flyw eightFactory |
|
|
|
|
|
|
|
|
|
|
|
• $Q$ $Q +W$] |
|
|
||
+ |
GetFlyweight(key) |
-flyweight |
|
Flyweight |
|
Context |
||
|
if (flyweight[key] exists) { |
1..* |
+ |
Operati on(extrinsi cState) |
|
Q |
|
|
|
return existing flyweight; |
|
|
|
||||
|
|
|
|
|
|
|
||
|
} else { |
|
|
|
|
|
|
|
|
create new flyweight; |
|
|
|
e U |
|
|
|
|
flyweights; |
|
|
|
|
|
||
|
add it to pool of |
|
|
|
|
|
|
|
|
return the new |
|
|
|
|
|
AbstractExpression |
|
|
|
|
|
• |
|
Client |
1..* |
|
|
} |
|
|
|
Y " # U !+ |
|||
|
flyweight; |
|
|
|
|
|
+ |
Interpret(Context) |
|
|
|
|
|
|
Q! |
|
|
|
|
ConcreteFlyw eight |
|
|
UnsharedConcreteFlyw eight |
|
|
|
|
|
|
|
|
|
|
|
|
|
- |
allState |
|
TerminalExpression |
|
NonTerminalExpression |
|
||
|
- |
intrinsicState |
|
|
|
||||||||
|
|
|
|
|
|
|
|
+ Interpret(Context) |
|
+ Interpret(Context) |
|
||
|
+ |
Operation(extrinsicState) |
|
|
+ |
Operation(extrinsicState) |
|
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Client |
p
[ !W$
•a !$ $*$U "
" $$ $+W \
! $*$ $Q$* \ ] * !+$h ] *
"$ $Q$] #
V$
•Y ] *$"U Q$
! "
) [$
[
•X$Q " #$]$^
$Z b$!+$ $"
^ \$
$$"$!* !*
e U
•Y " ^$! !+W #$ $
#$]$^
) [$
class Mediator |
|
|
|
-mediator |
|
Mediator |
Colleague |
|
ConcreteMediator |
ConcreteColleague1 |
ConcreteColleague2 |
) [$
[ !W$
•o$ $ $ $" ] ! lT * l
!$!
) s "
[
•V \ Z$" ^
\
|
) s " |
||||
class Memento |
|
|
|
||
|
Originator |
|
|
|
|
- |
state |
|
Memento |
|
|
|
|
- |
state |
-memento |
|
+ |
CreateMemento() : Memento |
Caretaker |
|||
|
|
||||
|
return new Memento(state) |
+ |
GetState() |
|
|
+ |
SetMemento(Memento) |
|
|||
+ |
SetState() |
|
|||
|
state = m->GetState() |
|
|||
|
|
|
|
) s "
[ !W$
•V$ $Z$!
" ls !l ! W$ $! ! ls l
V$
•Y$" ls #l *! "
$ Q " ]$ls l
] " "U # ^t Z
$] "$Q$
<73u:
class Proxy |
|
|
|
|
|
Subject |
|
|
+ |
Request() |
|
|
RealSubj ect |
-realSubject |
Proxy |
|
|
|
|
+ |
Request() |
+ |
Request() |
|
|
|
... |
|
|
|
realSubject->Request(); |
|
|
|
... |
Y$
[
•r " " ^ $ $
* ! *$ $
Y$
class State |
|
|
|
|
|
|
Context |
|
|
State |
|
|
-state |
|
|
|
|
+ |
Request() |
|
+ |
Handle() |
|
|
state->Handle() |
|
|
|
|
|
ConcreteStateA |
|
ConcreteStateB |
||
|
+ |
Handle() |
|
+ |
Handle() |
Y$
[ !W$
•v ! $W$ $
* Q$ $ $!+W$ $
\ ] !$ $ $ $
Y *
[
•Y " ]
*$*
e U
•X " ] * *$*
" #$$ $ $Z #$
Y *
class Strategy |
|
|
|
|
|
|
||
|
Context |
+strategy |
|
|
Strategy |
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
+ |
ContextInterface() |
|
|
+ |
AlgorithmInterface() |
|
|
|
|
|
|
|
|
|
|||
|
|
ConcreteStrategyA |
|
ConcreteStrategyB |
|
ConcreteStrategyC |
||
|
+ |
AlgorithmInterface() |
+ |
AlgorithmInterface() |
+ |
AlgorithmInterface() |
* ) #
[
•X " * " ]$"
\ U * *
$$ W #$! ! *
* ) #
class Template Method
|
|
AbstractClass |
+ |
Pri mitiveOperation1() |
|
+ |
Pri mitiveOperation2() |
|
+ |
TemplateMethod() |
|
|
|
... |
|
|
PrimitiveOperation1() |
|
|
... |
|
|
PrimitiveOperation2() |
|
|
... |
|
|
ConcreteClass |
|
+ |
PrimitiveOperation1() |
|
+ |
PrimitiveOperation2() |
|
|
f !* |
|
|
f !* |
|
|
• _\ !$ $ |
|
• |
[ * \ |
|
|
– Y ! ! |
|
|
Z \$ $ |
|
|
– [ ! |
|
|
– Y ! ! * |
|
– [ * ! |
|
|
– [ ! * |
|
|
|
|
|
||
|
|
– [ !$ $\ |
|
|
– [ * ! |
|
|
– [$Q +W #$ $ # |
|
• |
* * W w |
w W |
|
\ |
|
|
|
|
|
|
|
|
|
|
|
|
|
• |
m " $ |
|
|
|
|
• |
x * |
|
|
|
|
|
|
Many Paths to Disaster
Structured Programming
Artificial Intelligence
Networking Technologies
Open Systems
Parallel Processing
[ d
•y "U # * O-/ 5(00 3I @NB Y$ $
$ #$! ! #
•y O035$ y ]$# ^ ?3B 35R182
•y Z ?(6 I(8237: V "
$]$" #
•P Q \ z.DN2 F0NB/1 P Q$" $Z ] ] *
*
•e ! Z #$ z.217I(81 503(2 *
Z #$Q " W Q " !
$!W$
_d
•x$$Q$\ \ \
U #
•X !Q +$*$!Q * \ \ ] " ! !W
"$!Q \ *! "$
!Q +W \$ $
[ d
+,!$-./!!%",0 1 2."/1&%,$$ "/3"/4#!5#6 78
•f ,@3F1 (.B @-77376 f$*
! ! * "$Z!
•e ! [X ,3I2G(71 503(2 e U$!+W$ $ $"$t "U
"U$!$
+,!$-./!!%",0 1 "/3"/4#!5% 78
•$ $ 45627(82-3.-.)176-3. Y
$\$! # \$] \$#
•V t Q 4@5-/N3N6 )-1GD3-.2 [$ $Z t Q
$$
M