You are on page 1of 26

Unified Modeling Language

Chapter 4
Squeak: Object-oriented design
with multimedia applications
Unified Modeling Language

• There have been O-O gurus for many years


• Three of them worked together to define UML
(“Three amigos”: Booch, Rumbaugh, Jacobson)
• Has now been approved as a standard by the
Object Management Group (OMG)
• UML is a notation/language not a process
• Diagrams and notation from UML 1.4 definition;
1.5 is the latest; see:
http://www.rational.com/uml/resources/documentation/index.jsp

05/26/05 Copyright 2000, Mark Guzdial 2


Diagrams

• Class diagrams: Represents static structure


• Use case diagrams: Sequence of actions a
system performs to yield an observable result to
an actor
• Sequence diagrams: Shows how groups of
objects interact in some behavior
• State diagrams: Describes behavior of system
by describing states of an object
• Plus others

05/26/05 Copyright 2000, Mark Guzdial 3


UML Class Diagrams

• Classes are boxes Box


Pen
• Top is name size
heading
draw 1 1 location

• Middle are attributes undraw


drawColor:
pen
go:
place:
grow:

• Bottom is services
turn:
move:
moveTo:
turn:

• Lines are
relationships NamedBox
name

• Arrows show draw


undraw
drawNameColor:
navigability

05/26/05 Copyright 2000, Mark Guzdial 4


How can two classes be
related?

• Generalization-specialization or IsA
• NamedBox IsA Box
• Diagram: Triangle on the relationship line
• Association or HasA
• Box HasA Pen
• Diagram: Just a relationship line
• Aggregation is a part-whole relationship, but not exclusive
• Diagram: Open diamond on the line
• Composition is a part-whole relationship that is exclusive
• Diagram: Closed diamond on the line
• Dependency or TalksTo
• Dependency is sort of temporary HasA
• Diagram: Dashed line in UML

05/26/05 Copyright 2000, Mark Guzdial 5


The Aggregation-Association Issue

• It’s not clear when, in UML, you notate that one


thing “has” another.
• Coad: “An example of aggregation is the relationship
between an organization and its clerks”
• Rumbaugh: “A company is not an aggregation of its
employees”
• How many OO experts does it take…
• Safest: Use an association unless the definition
of “aggregation” is clear to your audience

05/26/05 Copyright 2000, Mark Guzdial 6


More on UML Class Diagrams

• Navigability
• Both ways or just one? Who knows about the other?
• Does the Box have the Pen or the Pen have the Box?
• Usually added later in the process
• Book is wrong on bidirectional (no arrows is
bidirectional, not double arrows.)
• Multiplicities
• How many Pens per how many Boxes?
• Can add labels to indicate how reference is
viewed

05/26/05 Copyright 2000, Mark Guzdial 7


Concrete and Abstract Classes

• Concrete classes are those that we create


instances from
• Abstract classes are never instantiated
• They exist to define structure and behavior for
other classes to inherit
• In UML, abstract classes use italics when
naming the class, or <<abstract>>
keyword
05/26/05 Copyright 2000, Mark Guzdial 8
Use Case Diagrams

• Means of capturing requirements


• Document interactions between user(s)
and the system
• User (actor) is not part of the system itself
• But an actor can be another system
• An individual use case represents a task
to be done with support from the system
(thus it is a ‘coherent unit of functionality’)
05/26/05 Copyright 2000, Mark Guzdial 9
Simple Use Case Diagram

Reserve book

Borrow book

Return book

05/26/05 Copyright 2000, Mark Guzdial 10


Use Case Diagram with
Multiple Actors

05/26/05 Copyright 2000, Mark Guzdial 11


Use Cases
• Are actually defined as text, including
descriptions of all of the normal and exception
behavior expected
• Do not reveal the structure of the system (i.e.
the system does…)
• Collectively define the boundaries of the system
to be implemented
• Provide the basis for defining development
iterations
• Use language of user

05/26/05 Copyright 2000, Mark Guzdial 12


Use Case Descriptions
USE CASE UC1: Process Sale
Primary Actor: Cashier
Stakeholders and Interests:
- Cashier: Wants accurate, fast entry, no payment errors
- Salesperson: Wants commissions updated
- Customer: Wants purchase and fast service. Wants proof
Preconditions: Cashier is identified and authenticated
Postconditions: Sale is saved. Tax correctly calculated. Accounting
and inventory are updated. Commissions recorded. Receipt is
generated. Payment authorizations are recorded.
Main Success Scenario:
1. Customer arrives at POS checkout with goods/services to buy
2. Cashier starts a new sale.
3. Cashier enters item identifier.
4. System records sale item and presents item description, price,
and05/26/05
running total. Price calculated
Copyright 2000,from a set of price rules.
Mark Guzdial 13
Use Case Descriptions
Cashier repeats steps 3-4 until indicates done
5. System presents total with taxes calculated.

Extensions / Exceptions:
*a. At any time, System fails:
To support recovery and correct accounting, ensure all
transaction sensitive state and events can be recovered from any
step of the scenario.
1. Cashier restarts System, logs in, and requests recovery of
prior
State : Restart System.
2. System reconstructs prior state.
3a. Invalid Identifier:
1. System signals error and rejects entry.
Special Requirements:
- Touch screen UI on large flat panel monitor, Text visible from 1
meter
05/26/05 Copyright 2000, Mark Guzdial 14
Sequence (Event) Diagrams

• Shows individual objects and how they


interact
• Describes
• Lifelines of objects
• Who sends what messages when
• Can also describe sending messages to self
("self-delegation")

05/26/05 Copyright 2000, Mark Guzdial 15


Example Real Time
Sequence Diagram

05/26/05 Copyright 2000, Mark Guzdial 16


State Diagrams

• Describe all the possible states a


particular object can get into, and the
events that lead to those changes
• Also called a "statechart"

05/26/05 Copyright 2000, Mark Guzdial 17


Example State Diagram

05/26/05 Copyright 2000, Mark Guzdial 18


UML in Real Practice

• You don't typically use all the diagrams


• You'll choose between them based on preference and
particular situation
• You typically use many diagrams
• A single use case may not capture all scenarios
• If you are going to use statecharts, there are probably
lots of objects with states
• Each sequence diagram only shows one interaction

05/26/05 Copyright 2000, Mark Guzdial 19


Example: Student
Registration System

• Not going to do all the diagrams


• Not all types, not even all that completely
specify the system
• But this is an application you know, so the
examples may help make sense

05/26/05 Copyright 2000, Mark Guzdial 20


Student Registration Class
Diagram (Early Analysis Level)
Student Transcript
1 historyRecordedIn 1

* getsScheduleFrom 1
Registrar gradeForCourse:
Section takenCourse:

assigns
enrollInClass: *
gradeInCourse: daysAndTime getSectionsFor:
takenCourse: roster enrollInSection:
* addStudent dropFromSection:
removeStudent * 1
majorsIn *
CourseGrade
taughtIn manages
1 1 *
1 givenFor * grade
Department Course termEnrolled
1..3 * *
owns name
requiredCourses number hasPrereqs
0..3
creditHours prereqs

05/26/05 Copyright 2000, Mark Guzdial 21


Partial Use Case Diagram

Apply for
Admission

Enroll in
the University Admissions

Student Enroll in
a Course

Withdraw
from a Course

05/26/05 Copyright 2000, Mark Guzdial 22


States of a Student
Apply [ Must be accepted first ]
Enrolled

EnrollInClass ( Add  a Transcript )

Withdraw Registered AddCourse

Graduate [ All courses must be completed ]

05/26/05 Copyright 2000, Mark Guzdial 23


Sequence Diagram:
Registering for Course
aStudent:  theRegistrar : aSection :  theTranscript :
Student Registrar Section Transcript
getSectionsFor:

return sections

enrollInSection:

takenCourse: prerequisite
state of prereq

[havePrereq] addStudent:

enrolled enrolled

05/26/05 Copyright 2000, Mark Guzdial 24


UML Tools

• Most complete tool: Rational Rose,


http://www.rational.com
• Lots of others
• Together by Object International
• BOOST (Basic Object-Oriented Support Tool)
by Noel Rappin, available on CD/CoWeb
• Argo-UML, ObjectPlant, Posiden, etc.
• diagramming tools, e.g. Visio, xfig
05/26/05 Copyright 2000, Mark Guzdial 25
For More Information…

• Serious O-O designers do use UML


• UML Distilled by Martin Fowler is a good
practical introduction to UML
• Official UML book series published by
Addison-Wesley
• UML Resource Center
• http://www.rational.com/uml/index.jsp

05/26/05 Copyright 2000, Mark Guzdial 26

You might also like