Using UML to express
Software Architecture
CSE 403, Spring 2007, Alverson
Outline
y
y
y
y
UML overview
UML class diagrams
Class exercise Ski school system
[Fri] UML sequence diagrams
CSE 403, Spring 2007, Alverson
Readings
y
Practical UML: A hands on introduction for
developers
http://dn.codegear.com/article/31863
If you want to learn more about UML,
there are a number of UML books (and
web tutorials) available, including UML
Distilled, by Martin Fowler.
CSE 403, Spring 2007, Alverson
UML
In an effort to promote Object Oriented designs, three
leading object oriented programming researchers
joined ranks to combine their languages:
o
o
o
Grady Booch (BOOCH)
Jim Rumbaugh (OML: object modeling technique)
Ivar Jacobsen (OOSE: object oriented software eng)
and come up with an industry standard [mid 1990s].
CSE 403, Spring 2007, Alverson
UML Unified Modeling Language
y
The result is large (as one might expect)
o Union of all Modeling Languages
Use case diagrams
Class diagrams
Object diagrams
Sequence diagrams
Collaboration diagrams
Statechart diagrams
Activity diagrams
Component diagrams
Deployment diagrams
.
But its a nice standard that has been embraced
by the industry.
CSE 403, Spring 2007, Alverson
UML class diagrams
UML class diagram:
a picture of the classes in an OO system,
their fields and methods, and
connections between the classes that
interact or inherit from each other
Does not include:
details of how the classes interact with each other
algorithmic details
how a particular behavior is implemented
CSE 403, Spring 2007, Alverson
Practice as we go
y
Complete the templates for a
o
Square
Length
Perimeter
Area
Circle
Radius
Perimeter
Area
CSE 403, Spring 2007, Alverson
Diagram of one class
y
class name in top of box
o
o
attributes
o
use italics for an abstract class name
+ <<interface>> if an interface class
should include all fields of the object
operations / methods
o
o
may omit trivial (get/set) methods
should not include inherited methods
CSE 403, Spring 2007, Alverson
Class attributes
y
attributes (fields, instance variables)
o
visibility name : type [count] = default_value
visibility:
underline static attributes
derived attribute: not stored, but can
be computed from other attribute values
+
#
~
/
CSE 403, Spring 2007, Alverson
public
protected
private
package (default)
derived
Class operations / methods
y
operations / methods
o
visibility name (parameters) : return_type
visibility:
underline static methods
parameter types listed as (name: type)
omit return_type on constructors and
when return type is void
+
#
~
CSE 403, Spring 2007, Alverson
public
protected
private
package (default)
Relationships btwn. classes
y
generalization: an inheritance relationship (isa)
o
o
inheritance between classes
interface implementation
association: a usage relationship
o
o
o
dependency
aggregation (class is formed as a collection of others)
composition (variant of aggregation when
a contained class will not exist without
the container class)
CSE 403, Spring 2007, Alverson
Generalization relationships
y
generalization (inheritance)
o
o
hierarchies drawn top-down with arrows
pointing upward to parent
line/arrow styles differ, based on whether
parent is a(n):
class:
solid line, black arrow
abstract class:
solid line, white arrow
interface:
dashed line, white arrow
CSE 403, Spring 2007, Alverson
Association relationships
association: an instance of one class must know about
the other in order to do its work
1.
multiplicity
y
y
y
y
2.
3.
* 0, 1, or more
1
1 exactly
2..4 between 2 and 4, inclusive
3..* 3 or more
name
navigability
CSE 403, Spring 2007, Alverson
(what relationship the objects have)
(direction of a query,
represented by a line between the objects
no arrow if communication flows both ways)
Multiplicity of associations
one-to-one
each student must carry exactly one ID card
one-to-many
each student may have many classes
CSE 403, Spring 2007, Alverson
Back to our example
y
Add a square-list class and associate it with a
square
Identify the multiplicity on the ends of the
association
y
y
y
y
* 0, 1, or more
1
1 exactly
2..4 between 2 and 4, inclusive
3..* 3 or more
CSE 403, Spring 2007, Alverson
ShoeStore
Association types
y
aggregation: contains
o symbolized by a clear white diamond
pointing to the class containing the other
aggregation
NikeShoes
class
composition: contained for only this purpose composition
o
o
o
stronger version of aggregation
the parts live and die with the whole
symbolized by a black diamond pointing to
the containing class
dependency: "uses temporarily"
o symbolized by dotted line
CSE 403, Spring 2007, Alverson
Hand
5
Finger
dependency
Lottery
Ticket
Random
Composition/aggregation example
If the movie theatre goes away
so does the box office => composition
but movies may still exist => aggregation
CSE 403, Spring 2007, Alverson
Class diagram example
No arrows; info can
flow in both directions
Aggregation Order
class contains
OrderDetail classes.
Could be composition?
CSE 403, Spring 2007, Alverson
UML example #2
Lets add the visibility attributes
CSE 403, Spring 2007, Alverson
UML square
comment
generalization
CSE 403, Spring 2007, Alverson
Something
seems wrong with
the visibility
and with the
constructor type?
Shall we try a bigger design?
Crystal Ski School
Crystal wants to implement a
new ski school booking/payment
mechanism
They want to allow students to
request particular instructors,
and see their availability
They want to allow instructors to
retrieve their daily schedule
They want to allow invoicing on
a monthly basis
CSE 403, Spring 2007, Alverson
What would be our main
y
Objects
Connections
CSE 403, Spring 2007, Alverson