Documente Academic
Documente Profesional
Documente Cultură
Christine Julien
EE461L
Figures from Head First Design Patterns
on design
Best known: Gang of Four (Gamma, Helm, Johnson,
Vlissides)
Design Patterns: Elements of Reusable Object-Oriented Software
Caveats
Design patterns are not a substitute for thought
Class names and directory structures do not equal good
design
Design patterns have tradeoffs
Well talk about the mediator pattern. It does not remove complexity
of class hierarchies
Participants
classification
Intent
Also known as
Justification
Applicability
Structure
Collaborations
Consequences
Implementation
Sample code
Known uses
Related patterns
SimUDuck
The ducks
should be
able to swim!
What about a
readheaded
duck?
Dont
ducks fly,
too?
We should
have Mallard
ducks!
The ducks
should
quack!
SimUDuck, Take 2
Lets use an
interface!
I need to control
the quacking
volume. Make the
quack method
take a volume.
10
Design Principles
Identify the aspects of your application that vary and
11
12
or in UML
13
Program to an interface
14
15
16
17
Whats a Duck?
public class Duck {
QuackBehavior quackBehavior;
// more
public void performQuack() {
quackBehavior.quack();
}
}
18
19
code.
Play with MiniDuckSimulator and
MiniDuckSimulator1
20
21
An Exercise
(This should be a quick one)
How would you make a duck call device without inheriting
22
23
24
QUESTIONS?