CREATE Design Class Diagrams (DCDs)

advertisement
Design Model:
Design Class Diagrams
Larman chapter 19
1
Design Class Diagrams
• Objectives:
– CREATE Design Class Diagrams (DCDs)
– Identify the classes, methods and associations to
show in a DCD.
2
Design Class Diagrams
how?
• DCDs are created in parallel with the creation
of Interaction Diagrams
• First sketch out relevant classes, method
names and relationships, then do a little
interaction diagramming, then update DCDs,
then extend the interaction diagrams some
more, and so on.
3
Design Class Diagrams
example
Three section box for
class definition.
Navigability
Sale
Register
Captures
1
1
date
isComplete : Boolean
time
enterItem(...)
makeLineItem(...)
methods; there are parameters, but unspecified
type information
4
Domain Model vs. Design Model
Concept; conceptual class
Sale
Register
Captures
1
Domain Model
1
Register
Sale
...
Design Model
endSale()
enterItem(...)
makePayment(...)
date
isComplete : Boolean
time
Captures
1
1
date
isComplete : Boolean
time
makeLineItem(...)
software class
5
Creating a DCD
•
Identify those classes that participate in the
software solution:
1. Scan all the Interaction Diagrams and list the
classes mentioned
2. Draw a class diagram for these classes and include
the attributes previously identified in the Domain
Model
3. Add method names
4. Add more type information
5. Add associations and navigability
6. Add dependency relationships
6
1. Scan all the Interaction Diagrams
and list the classes mentioned:
•
•
•
•
•
•
•
Register
ProductCatalog
ProductSpecification
Payment
Store
Sale
SalesLineItem
7
2.
Draw a class diagram for these classes and include
the attributes previously identified in the Domain
Model
Register
ProductCatalog
description
price
itemID
...
...
ProductSpecification
...
Payment
amount
...
...
Store
address
name
Sale
date
isComplete
time
SalesLineItem
quantity
...
...
...
8
3. Add method names:
Sale
...
makeLineItem(...)
:Register
2: makeLineItem(spec, qty)
:Sale
9
3. Add method names:
Register
ProductCatalog
...
...
endSale()
enterItem(...)
makeNewSale()
makePayment(...)
getSpecification()
Store
address
name
addSale(...)
ProductSpecification
description
price
itemID
Payment
amount
...
...
Sale
date
isComplete
time
SalesLineItem
quantity
becomeComplete()
makeLineItem(...)
makePayment(...)
getTotal()
getSubtotal()
10
3. Add method names:
• Create methods:
– It is common to omit creation-related methods and
constructors from DCDs because of its multiple
interpretations in different object oriented languages
and also because initialization is a very common
activity
• Accessing methods:
– ’Get’ and ’Set’ methods are usually omitted because
of the high noise-to-value ratio they generate (e.g.
getPrice in ProductSpecification)
11
3. Add method names:
• multiobjects:
1: spec := getSpecification(id)
:Product
Catalog
1.1: spec := find(id)
The find message is to the
container object, not to a
ProductSpecification.
:Product
Specification
12
4.
Add more type information:
Register
ProductCatalog
ProductSpecification
...
...
endSale()
enterItem(id : ItemID, qty : Integer)
makeNewSale()
makePayment(cashTendered : Money)
getSpecification(id: ItemID) : ProductSpecification
...
Store
address : Address
name : Text
description : Text
price : Money
itemID : ItemID
Sale
SalesLineItem
date : Date
isComplete : Boolean
time : Time
quantity : Integer
getSubtotal() : Money
addSale(s : Sale)
becomeComplete()
makeLineItem(spec : ProdSpecification , qty : Integer)
makePayment(cashTendered : Money)
getTotal() : Money
Payment
amount : Money
...
Return type of method
void; no return value
13
5.
Add associations and navigability :
Register class will
have an attribute pointing to a
Sale object.
Navigability arrow indicates
Register objects are
connected uni-directionally to
Sale objects.
Sale
Register
the currentSale
attribute is often
excluded, as it is
implied by the
navigable
association from
Register to Sale.
currentSale : Sale
endSale()
enterItem(...)
makeNewSale()
makePayment(...)
1
date
isComplete
time
Captures
1
becomeComplete()
makeLineItem(...)
makePayment(...)
getTotal()
Absence of navigability
arrow indicates no
connection from Sale to
Register.
14
5.
Add associations and navigability :
• Required visibility and associations between
classes are indicated by the Interaction
Diagrams
• Associations are needed between A and B if:
– A sends a message to B
– A creates an instance of B
– A need to maintain a connection to B
15
5.
Add associations and navigability :
create()
:Store
1: create()
2: create(pc)
:Register
1.1: create()
1.2.2*: add(ps)
pc:
ProductCatalog
1.2:
loadProdSp
ecs()
:Product
Specification
1.2.1*: create(id, price, description)
ps:
ProductSpecification
16
6.
Add dependency relationships:
Store
1
Uses
1
address : Address
name : Text
1
ProductSpecification
ProductCatalog
addSale(...)
1
Looks-in
1
Contains
...
1..*
1
description : Text
price : Money
itemID: ItemID
getSpecification(...)
...
Houses
1
1
Sale
Register
...
Logs-completed
1
*
date : Date
isComplete : Boolean
time : Time
Captures
endSale()
enterItem(...)
makeNewSale()
makePayment(...)
1
Describes
1
becomeComplete()
makeLineItem(...)
makePayment(...)
getTotal()
*
A dependency of Register knowing about
ProductSpecification.
SalesLineItem
Contains
1..*
1
quantity : Integer
getSubtotal()
1
Payment
Paid-by
1
amount : Money
...
Recommended when there is parameter,
global or locally declared visibility.
17
Notation for member details
SampleClass
classAttribute
+ publicAttribute
- privateAttribute
attributeWithVisibilityUnspecified
attribute1 : type
burgers : List of VeggieBurger
attribute2 : type = initial value
finalConstantAttribute : int = 5 { frozen }
/derivedAttribute
classMethod()
+ «constructor» SampleClass(int)
methodWithVisibilityUnspecified()
methodReturnsSomething() : Foo
abstractMethod()
abstractMethod2() { abstract } // alternate
+ publicMethod()
- privateMethod()
# protectedMethod()
~ packageVisibleMethod()
finalMethod() { leaf }
methodWithoutSideEffects() { query }
synchronizedMethod() { guarded }
method1WithParms(in parm1:String, inout parm2:int)
method2WithParms(parm1:String, parm2:float)
method3WithParms(parm1, parm2)
method4WithParms(String, int)
methodWithParmsAndReturn(parm1: String) : Foo
methodWithParmsButUnspecified(...) : Foo
methodWithParmsAndReturnBothUnspecified()
java.awt.Font
plain : Integer = 0 { frozen }
bold : Integer = 1 { frozen }
name : String
style : Integer = 0
...
+ getFont(name : String) : Font
+ getName() : String
...
java.awt.Toolkit
or
java.awt.Toolkit { abstract }
...
«interface»
Runnable
run()
AlarmClock
run()
...
// there are attributes, but not shown
# createButton(target : Button) : ButtonPeer
+ getColorModel() : ColorModel
...
FinalClass { leaf }
an empty
compartment
without ellipsis
means there is
definitely no
members (in
this case, no
attributes)
... // there are methods, but not shown
18
Member details in POS
Register
ProductCatalog
...
...
+ endSale()
+ enterItem(...)
+ makeNewSale()
+ makePayment(...)
+ getSpecification(...)
Store
- address
- name
+ addSale(...)
Sale
- date
- isComplete
- time
+ becomeComplete()
+ makeLineItem(...)
+ makePayment(...)
+ getTotal()
Payment
ProductSpecification
- description
- price
- itemID
- amount
...
...
SalesLineItem
- quantity
+ getSubtotal()
19
Notation for method bodies in DCDs
UML notation:
A method body implementation may be shown in a UML note box. It should be placed within braces, which
signifies it is semantic influence (it is more than just a comment).
The synax may be pseudo-code, or any language.
It is common to exclude the method signature (public void ...), but it is legal to include it.
{
Register
ProductSpecification spec = catalog.getSpecification(id);
sale.makeLineItem(spec, qty);
}
...
endSale()
enterItem(id, qty)
makeNewSale()
makePayment(cashTendered)
{
public void enterItem( id, qty )
{
ProductSpecification spec = catalog.getSpecification(id);
sale.makeLineItem(spec, qty);
}
}
20
Sample UP Artifact Relationships for Design Class Diagrams
Domain Model
Register
1
Sale
1
...
inspires
the names
and
attributes
of some
software
classes in
the design
...
date
...
suggests domain
concepts
...
Use-Case Model
requires UCRs
Design Model
: Register
: ProductCatalog
use-case
realizations
(UCRs)
makeNewSale()
enterItem
(itemID, quantity)
spec := getSpecification( itemID )
...
the design classes
discovered while
designing UCRs are
summarized in DCDs
Register
ProductCatalog
...
...
makeNewSale()
enterItem(...)
...
*
1
getSpecification(...)
...
Sale
date
...
design
class
diagrams
(DCDs)
...
...
...
...
21
Download