DCDs - Rose

advertisement
CSSE 374:
Design Class Diagrams
Steve Chenoweth
Office: Moench Room F220
Phone: (812) 877-8974
Email: chenowet@rose-hulman.edu
Chandan Rupakheti
Office: Moench Room F203
Phone: (812) 877-8390
Email: rupakhet@rose-hulman.edu
These slides and others derived from Shawn Bohner, Curt Clifton,
Alex Lo and others involved in delivering 374.
CS humor…
General solutions get you a 50% tip
Plan for the Day, when we get to class

Initial course comments
– a fun exercise!

Design Class Diagrams

Design exercise that
should help with
Homework #2
Help Me Help You
help me help you…

Initial course comments –
take out a piece of paper!

List one helpful idea about the course:
 Especially
good, fun or useful thing
 Especially need fixing thing
 New idea for us to try

Then…
…George
Washington &
Betsy Ross
realizing that
design matters!
UML Class Diagrams
http://www.cartoonbank.com/1993/betsy-ross-and-george-washington-looking-over-a-variety-of-flag-designs/invt/107338/
Design Class Diagrams (DCD)

1/2
Creation of DCDs
builds on prior:
 Domain
Model (+detail
to class definitions)
 Interaction diagrams
(identifies class
methods)

Creation of DCDs and
interaction diagrams
are usually created in
parallel
Q1
Design Class Diagrams (DCD)
DCDs illustrates the
specifications for
software classes and
interfaces including:






Classes, associations,
and attributes
Interfaces, with their
operations and constants
Methods
Attribute type information
Navigability
Dependencies
2/2
SuperclassFoo
or
SuperClassFoo { abstract }
3 common
compartments
1. classifier name
2. attributes
3. operations
an interface
shown with a
keyword
«interface»
Runnable
run()
- classOrStaticAttribute : Int
+ publicAttribute : String
- privateAttribute
assumedPrivateAttribute
isInitializedAttribute : Bool = true
aCollection : VeggieBurger [ * ]
attributeMayLegallyBeNull : String [0..1]
finalConstantAttribute : Int = 5 { readOnly }
/derivedAttribute
+ classOrStaticMethod()
+ publicMethod()
assumedPublicMethod()
- privateMethod()
# protectedMethod()
~ packageVisibleMethod()
«constructor» SuperclassFoo( Long )
methodWithParms(parm1 : String, parm2 : Float)
methodReturnsSomething() : VeggieBurger
methodThrowsException() {exception IOException}
abstractMethod()
abstractMethod2() { abstract } // alternate
finalMethod() { leaf } // no override in subclass
synchronizedMethod() { guarded }
officially in UML, the top format is
used to distinguish the package
name from the class name
unofficially, the second alternative
is common
Common UML
Class
Notation
java.awt::Font
or
java.awt.Font
plain : Int = 0 { readOnly }
bold : Int = 1 { readOnly }
name : String
style : Int = 0
...
getFont(name : String) : Font
getName() : String
...
Fruit
dependency
...
...
interface
implementation
and
subclassing
SubclassFoo
PurchaseOrder
1
...
run()
...
- ellipsis “…” means there may be elements, but not shown
- a blank compartment officially means “unknown” but as a
convention will be used to mean “no members”
...
order
...
association with
multiplicities
Recipe for a Design Class Diagram
1) Identify all the classes participating in the software
solution by analyzing the interaction diagrams
2) Draw them in a class diagram
3) Duplicate the attributes from the associated concepts
in the conceptual model
4) Add method names by analyzing the interaction
diagrams
5) Add type information to the attributes and methods
6) Add the associations necessary to support the
required attribute visibility
7) Add navigability arrows to the associations to indicate
the direction of attribute visibility
8) Add dependency relationship lines to indicate nonattribute visibility
Class Diagrams Do Double Duty
Sale
Domain Model
conceptual
perspective
Register
...
1
Captures
Multiplicity only at target end
1
Navigability arrow
Register
Design Model
...
DCD; software
perspective
endSale()
enterItem(...)
makePayment(...)


time
isComplete : Boolean
/total
Sale
time
isComplete : Boolean
currentSale /total
1
makeLineItem(...)
Role name
at target
Call them Domain Models
whenonly
used
for end
analysis at the conceptual level
No association name
Call them Design Class Diagrams when used
for design
Q2
Attribute Text vs. Association Line Notation
using the attribute
text notation to
indicate Register has
a reference to one
Sale instance
currentSale : Sale
...
...
...
Avoid
OBSERVE: this style
visually emphasizes
the connection
between these classes
Role name is attribute name
Register
Sale
1
...
currentSale
...
Preferred
thorough and
unambiguous, but some
people dislike the
possible redundancy
Sale
Register
...
...
using the association notation to indicate
Register has a reference to one Sale instance
Register
currentSale : Sale
...
Sale
1
currentSale
...
...
Avoid
Q3
Guideline Good Practice: Example
Q4
Showing Collection Attributes
Multiplicities
Preferred, less visual clutter
Constraints
Q5
Operations

Syntax:



Also use syntax of implementation language


visibility name(paramName:type, …) : returnType {properties}
+ getPlayer(name:String) : Player {exception IOException}
public Player getPlayer(String name) throws IOException
Operation vs. operation contract vs. method
Cartoon of the Day
http://www.brickfetish.com/toys/duck.html
Keywords Categorize Model Elements
Keyword
Meaning
«actor»
classifier is an actor
«interface»
classifier is an
interface
shows that classifier is an actor
without getting all xkcd 
«interface»
MouseListener
{abstract}
can’t be instantiated
follows classifier or operation
set of objects has
defined order
can’t be extended or
overridden
follows role name on target end
of association
{ordered}
{leaf}
Example Usage
follows classifier or operation
Generalization

In Domain Model:
 Says
that the set of all
NumberCards is a subset of
the set of all Cards

In DCD:
 Says
that, and that
NumberCard inherits
from Card
Dependencies
Dependency lines are dashed
Attribute association
lines are solid
Use dependency lines when a more
specific line type doesn’t apply.
Can label dependency arrows:
e.g. «call», «create»
Q6
Interfaces in UML
socket line notation
Window1
Timer
Window1 uses the Timer
interface
dependency line notation
it has a required interface
Window2 has a dependency on the
Timer interface when it collaborates
with a Clock2 object
«interface»
Timer
Clock2
...
getTime()
Timer
Window2
Timer
Window3
getTime()
...
Clock1
implements and
provides the
Timer interface
Clock1
...
getTime()
...
Clock3
...
getTime()
...
socket line notation
lollipop notation indicates Clock3 implements
and provides the Timer interface to clients
Timer is a provided interface
Window3 has a dependency on the
Timer interface when it collaborates
with a Clock3 object
Q7
Composition

More powerful than an attribute arrow
Describes “whole-part” relationship

Implies

 Instance
of part belongs to only one composite at a
time
 Part always belongs to a composite
 Composite creates/deletes parts
Association name in composition is always implicitly
some “has-part” relation. So, it’s common to omit
association or role name with compositions
Q8
Interaction Diagrams and
Class Diagrams (DCD’s)

Interaction diagrams show dynamic behavior

Class diagrams show static behavior

Tips:
 Draw
concurrently
 Use
two adjacent whiteboards, one for static and
one for dynamic
 Sketch
communication diagrams, document using
sequence diagrams
Exercise on DCD’s

Break up into your
project teams

Given the following:
 Domain
Model and a
Sequence Diagram

Draw Design Class Diagram
showing a Customer and the classes in a
Rental package and a Video package for
BrickBusters Video Store. Try to minimize
dependencies.
Q9
Contains
1
1 Baske
t
0..* VideoDescription
title
subjectCategory
VideoSupplier
address
name
newVideos
1
Provides
1
0..*


Provides
HoldsDescribes
videos-in
Selects 
1 1
1
*
*
Rents-from,
Customer
Store
1 name
Video
Buys-from
Stocks
Address 1


*
address
*
1 Phone#
* ID
phone#
1
* *
1 1
1
1
Shelf
1 1 Membership


* location 1

*
ID
StoresObtains
Maintains
Contains
startDate
stock
 video-on
MakesDefines *
Authorizes
DeterminesPricingPolicy

1 rental-charge
perDayRentalCharge


perDayLateCharge
RecordsInitiates 
rental-of 0..*
*
Payment
Rental
Transaction
Transacts
/amount: Money
Pays-for
dueDate
date
 1..* ReturnDate

1
1
1
1..* type
authorization
ReturnTime
An SD Solution for Rent Video Example
:Customer
:Video
:Video
Description
rentVideos
Loop
[more items]
findVideoToRent(ID,duration)
videoTitle, availability
getVideoInfo(ID,duration)
videoTitle, desc, availabilty
selectVideoToRent(ID)
selectedVideos(video List)
Checkout
updateAvailability(ID,duration)
totalWithTaxes
+/∂ Feedback

On a separate piece of paper –
Please give us some team-levelanonymous feedback!
Possible topics –  Projects
 Class
 Schedule
 Quizzes
…
 Homework
 Anything
else
 Book
+ = things going well
∂ = things to fix
Thanks –
We’ll show results next class!
A CD Solution for Rent Video Example
rentVideos
:Customer
1: FindVideoToRent(ID,duration)
2: selectVideoToRent(ID)
3: Checkout
1.3: videoTitle, availability
3.1: selectedVideos(video List)
:Video
3.2: totalWithTaxes
1.1: getVideoInfo(ID,duration)
1.2: videoTitle, desc, availabilty
2.1: updateAvailability(ID,duration)
:Video
Description
Download