Domain Model : Adding Attributes

Download Report

Transcript Domain Model : Adding Attributes

Domain Model : Adding
Attributes
Larman ch. 12
larman ch. 12
1
Attributes
• Attribute = a logical data value of an
object.
• Include the following attributes in a domain
model :
– Those for which the requirements (ex. Use
cases) suggest or imply a need to remember
information.
– Ex. A receipt normally has a date and time.
larman ch. 12
2
Valid attribute types
• Keep it simple
– Prefer simple
attributes or data types
• Boolean, Date, Number,
String….
• Relate conceptual
classes with an
association
Cashier
not a "simple" attribute
Worse
name
currentRegister
Cashier
Better
1
Uses
name
Register
1
number
Flight
destination is a complex
concept
Worse
destination
Better
Flight
1
Flies-to
1
Airport
– not with an attribute
larman ch. 12
3
Simple attributes
• Make it an attribute if it is naturrally
thought of as number, string, boolean,
time….
– Otherwise represent it as a separate
conceptual class rather than as an attribute
• If in doubt, define something as a sepate
conceptual class rather than as an
attribute.
larman ch. 12
4
Non-primitive data type classes
• Represent as a non-primitive class if :
– It is composes of separate sections
• Phone number, name, …
– There are operations associated with it.
– It has other attributes
– It is a quantity with a unit
• That means :
– Address and Quantity are data types that can be considered as
separate classes.
– But it depends on what you wants to emphasize in the diagram
• It may be shown in the attribute of the class box.
– A domain model is a tool of communication
OK
OK
Product
Specif ication
Product
Specif ication
1
1
ItemID
Store
1
1
Address
Store
address : Address
id : ItemID
larman ch. 12
5
No attributes as foreign keys
• Do not use attributes as foreign keys.
– Use associations to relate an object to another
object.
Cashier
a "simple" attribute, but being
used as a f oreign key to relate
to another object
Worse
name
currentRegisterNumber
Cashier
Better
name
larman ch. 12
1
Uses
1
Register
number
6
Attributes in the NextGen Domain
Model
Register
Item
Store
address : Address
name : Text
Sales
LineItem
Cashier
Customer
Product
Catalog
Product
Specif ication
Sale
date : Date
time : Time
Manager
quantity : Integer
Pay ment
amount : Money
larman ch. 12
description : Text
price : Money
id: ItemID
7
Derived attributes
SalesLineItem
SalesLineItem
SalesLineItem
0..1
Records-sale-of
1
0..1
Records-sale-of
1..*
0..1
Records-sale-of
1..*
Item
Each line item records a
separate item sale.
For example, 1 tof u package.
Item
Each line item can record a
group of the same kind of
items.
For example, 6 tof u packages.
Item
/quantity
deriv ed attribute f rom
the multiplicity v alue
larman ch. 12
8
A partial domain model
Records-sale-of
Described-by
1
Product
Specif ication
Product
Catalog
Contains
1
1..*
1
0..1
description
price
itemID
Used-by
*
Describes
*
Sales
LineItem
*
Store
Item
Stocks
quantity
1
address
name
1
*
1..*
1..*
Logscompleted

Contained-in
1
*
Sale
1
Register
1
Pay ment
1
1
1
Captured-on
time
Paid-by
Manager
Started-by
date
1
Houses
1..*
1
1
Initiated-by
1
Customer
1
 Records-sales-on
1
Cashier
amount
larman ch. 12
9