**** Be sure you know the following fact:
- An activity and a state is shown as a box with rounded corners. They
are not boxes(classes or objects). They are not ovals,
these are use cases. Actions do things and have rounded corners.
Review UML Icons
Exercise: Write down what does each symbol above probably means...
Answers: click the letter: A B C D E F G H I
or select
[ 17exans.html ]
for all the answers + the diagram.
Review GRASP Patterns
Can you list all nine GRASP patterns without following the next
link:
[ 16answer.html ]
Here is a PDF file from another university that reviews the previous
GRASP patterns
[ cs489-13ch18.pdf ]
*** Interfaces
The GoF patterns use a lot of interfaces. Here are some notes on them.
An interface is a class that has not data but declares some operation.
It does not give any
implementation for the operations. If
an object fits an interface then you know how to call its functions but
the implementer can do different things with them. The client who uses
the interface is restricted to just using the listed functions. It is said
to
depend on the interface
or equivalently to
require the interface.
The classes that
implement the interface
are also said to require it.
In UML there are two or three notations, and
Larman covers them on pages 263 and 264.
The
lollipop notation
is a very simple way to show that a class implements an interface.
Here is an interface (Animate) and three classes that implement it.
This shows three classes that all
implement the same set of operations. Other classes can then use the operation.
You can use the standard dependency arrow ( - - - - > ) to
connect a class that requires the interface to the interface.
This relation is shown with a dotted line
or with a cup notation (new and rare).
Video Introducing the GoF Design Patterns
[ watch?v=M9zUjF65sho ]
GoF Key points
- GRASP helps you understand GoF Patterns
- The GoF patterns improve your grasp of GRASP.
- Good developers use the GoF names, so you need to know them.
GoF Patterns
The Gang of Four Patterns are all clever ways to use polymorphism
to make it easier to change code. They are often modeled using
the UML (class diagrams and interaction diagrams) plus English.
26 Applying GoF -- Adapter Factory Singleton Strategy Composite Observer
- Introduction
- ** 26.1
Adapter
(GoF)
[ patterns.html#Adapter ]
[ fig25_25_1.cpp ]
[ test.fig25_25_1.cpp ]
- ** 26.2 GRASP supports and explains GoF
See figure 26.3
- 26.3 Analysis in Design!?
Development is "Research and Development".... embrace change.
- ** 26.4
Factory
(GoF)
[ patterns.html#Factory ]
- ** 26.5
Singleton
(GoF)
[ patterns.html#Singleton ]
"One is one, and all alone, and ever more shall be."
Probably the most hated GoF pattern. Code:
[ singleton.cpp ]
[ test.singleton.cpp ]
- 26.6 Conclusion: handling many external services thru one interface
- ** 26.7
Strategy
(GoF)
[ patterns.html#Strategy ]
Example: many ways of sorting... Associate the algorithms to little objects.
Use different objects as needed.
- ** 26.8
Composite
(GoF) etc.
[ patterns.html#Composite ]
- (The example on page 452 is just the kind of thing that happens when my
wife (a senior 10% off) buys something with a Club Card (20% off!) on Tuesday
nights (10% off) in a certain Department store in San Bernardino...
- Figure 26.14 page 454: count the relations connecting
CompositePricingStrategy and ISalePricingStrategy.
- Figure 26.15 page 455 refers about a special way to indicate an object
of an unknown class but that implements an interface. I can not find this
notation anywhere in the latest (2007) standards. The standard lets
you show a lifeline with the name of an interface or a class with
no symbolic difference. Ambler shows a message that hits a little
interface lollipop -- but I think KISS.
- Figure 26.16 page 456: missing italics!
- ++ Composite is a good way to handle complex and changing business rules.
- ++ Composite is a way of encoding formulae and expressions as a set of linked objects:
[ Question 5 in 05a ]
- Figures 26.18 and 26.19, pages 458 and 459: a ref refers to a
sd -- sequence diagram.`
- * 26.9
Facade
(GoF)
A facade is a kind of curtain used for dramatic effect.
"The Wizard of Oz": Pay no attention to the system behind the facade.
[ patterns.html#Facade ]
- * 26.10
Observer
(GoF)
[ patterns.html#Observer ]
[ watch?v=Xxvpwmc-7io ]
- *** page 460
IDs to Objects
I didn't pay much attention to this common practice until March 2008
when I linked it to designing logins (handout). I think
(guess) that this should become a GRASP style pattern
- Who should find objects given their ID.
- The creator of the objects.
You could claim that this is merely putting Information Expert to work.
- * 26.11 Conclusion: GRASP supports GoF
- 26.12 Resources
[ patterns.html ]
- For a video introduction to a dozen design patterns see
[ watch?v=oSSGDYJZ-m8 ]
on YouTube.
Exercises on GoF Patterns
Chapter 30 Relating Use Cases -- YAGNI