Upload
alexis-edwards
View
220
Download
1
Tags:
Embed Size (px)
Citation preview
Jan 21, 2002 91. 3913 Ron McFadyen 1
Ch 10. Domain Model: Visualizing Concepts
Domain model
• illustrated with a class diagram (with no operations defined)
• emphasis on real-world objects
• a visual dictionary
• a map of concepts in a domain
• contains
• (conceptual) classes from the problem domain
• associations
• attributes
Jan 21, 2002 91. 3913 Ron McFadyen 2
Ch 10. Domain Model: Visualizing Concepts
Domain model
• Bottom of Page 138
•“ … the most common mistake when creating a domain model is to represent something as an attribute when it should have been a concept. “
If we do not think of some conceptual class X as a number or text in the real world, X is probably a conceptual class, not an attribute.
Jan 21, 2002 91. 3913 Ron McFadyen 3
Identifying conceptual classes
Linguistic analysis
• identify the nouns present in Use Cases and other descriptions
Using analysis patterns (advanced)
• Analysis Patterns, Fowler 1995
• Data Model Patterns, Hay 1996 Read th
ese books
(next y
ear or s
o)
Jan 21, 2002 91. 3913 Ron McFadyen 4
Identifying Classes
Books and journals The library contains books and journals. It may have several copies of a given book. Some of the books are for short term loans only. All other books may be borrowed by any library member for three weeks. Members of the library can normally borrow up to six items at a time, but members of staff may borrow up to 12 items at one time. Only members of staff may borrow journals.
Borrowing The system must keep track of when books and journals are borrowed and returned, enforcing the rules described above
Noun Identification
Jan 21, 2002 91. 3913 Ron McFadyen 5
Identifying Classes - candidate list
library
book
journal
copy of a given book
short term loan
library member
week
Member of the library
item
time
member of staff
system
rule
discard - outside scope
discard - not an object (yet, anyway)
discard - redundant see “Members of the library”
discard - not a thing (here)
discard - too vague, turns out to be book or journal
discard - outside scope
discard - part of the meta-language, not part of the domain
discard - part of the meta-language
Jan 21, 2002 91. 3913 Ron McFadyen 6
Identifying Classes - result
book
journal
copy of a given book
Member of the library
member of staff
Domain Classes
The domain is the application area we are working in
These classes describe our problem space
Natural classes from the problem space the user can appreciate
Jan 21, 2002 91. 3913 Ron McFadyen 7
Identifying Objects - result
book
journal
copy of a given book
Member of the library
member of staff
Class Diagram
We can place these in a diagram and illustrate how they are related by creating the appropriate associations
Jan 21, 2002 91. 3913 Ron McFadyen 8
A Class Diagram
Book
CopyLibraryMember
MemberOfStaff Journal
0..1 0..*
0..1 0..*
1..*
1is a copy of
borrows/returns
borrows/returns
Jan 21, 2002 91. 3913 Ron McFadyen 9
Ch 10. Domain Model: Visualizing Concepts
Flight
destination
arrival
vsFlight
destination
arrival
Airport
Destination and arrival airports as attributes
Destination and arrival airports as assocations
Preferred
Jan 21, 2002 91. 3913 Ron McFadyen 10
Specification (Description) conceptual classes
P. 142: Include a specification class when
• we need a description of something irrespective of its existence
• deletions result in loss of information
• it reduces duplicated information
Sale
SaleLineItem ProductSpecification
Jan 21, 2002 91. 3913 Ron McFadyen 11
Specification (Description) conceptual classes - Airline Example
Flight is a class that keeps track of flight number, date and time for a flight, departure and arrival airports.
departs from
arrives in arrival
departure
*
* 11
Flight
numberdatetime
nameaddress
Regardless of the date/time of a flight, the number and the airports involved stay constant.
Airport
Jan 21, 2002 91. 3913 Ron McFadyen 12
Specification (Description) conceptual classes - Airline Example
Flight
datetime
Larman suggests the use of a Description/Specification Conceptual Class to hold these attributes
- to avoid an anomaly relating to information disappearing due to objects being deleted.
FlightDescription
number*
1
departs from
arrives in arrival
departure
*
* 11
nameaddress
Airport
Jan 21, 2002 91. 3913 Ron McFadyen 13
Page 164:
• Focus on those associations for which knowledge of the relationship needs to be preserved for some duration
• “need-to-know” associations
• Avoid showing redundant or derivable associations
Associations
• correspond to verbs expressing a relationship between classes• objects do not exist in isolation - they fit together in some way
Jan 21, 2002 91. 3913 Ron McFadyen 14
“need-to-know” associations
Flight
datetime
Our database needs to record, to keep track of, when flights are scheduled, where they fly from and to - I.e. we need to know (or be able to derive) this information.
FlightDescription
number*
1
departs from
arrives in arrival
departure
*
* 11
nameaddress
Airport
Jan 21, 2002 91. 3913 Ron McFadyen 15
no redundant associations
departs from
arrives inarrival
departure
Flight
datetime
nameaddress
We can always derive the departure and arrival airports for a flight, so we don’t need to have these 2 redundant relationships
AirportFlightDescription
number*
1
*
*
1
1
arrival
departure
Jan 21, 2002 91. 3913 Ron McFadyen 16
*
0..1
Page 158: “ a person can be Married-to only one other person at any particular moment, even though ...
Person
is Married to
?
Multiplicity
Jan 21, 2002 91. 3913 Ron McFadyen 17
*
0..1
Page 158: “ the car is only Stocked-by one dealer ...
Car
Stocked-by
?
Dealer
Multiplicity
Jan 21, 2002 91. 3913 Ron McFadyen 18
1
0..1
Page 159: “ … The answer depends on our interest in using the model ...
Store
Stocks
?
Item
Multiplicity
*
Jan 21, 2002 91. 3913 Ron McFadyen 19
Page 160:
?0..11Person
Supervises
Multiplicity
*
Jan 21, 2002 91. 3913 Ron McFadyen 20
• Pages 156, 162: “association checklist”• typical ways in which associations arise
• A is physically contained in B … Section in a Book
• A is an organizational subunit of B … Faculty in a University
• etc
Associations
Jan 21, 2002 91. 3913 Ron McFadyen 21
P. 165 :
Larman indicates that some of these may not be needed
- not really part of the requirements
- may not need-to-know all that are shown here
Associations
Jan 21, 2002 91. 3913 Ron McFadyen 22
• attributes are preferably primitive (or just data types)
boolean, date, number, string, ...
Invoice
invDate: date
Attributes
Jan 21, 2002 91. 3913 Ron McFadyen 23
• Non-primitive types• where the associated things don’t need to be distinguished, such as phone number, quantities, points …•the abstraction makes sense in the problem domain
• a phone number has many parts• an item number that has subparts in its encoding• price is a Currency• amount is a Currency• qty_ordererd is a Quantity• these make sense in the problem domain• price * qty_ordered makes sense
Attributes
Jan 21, 2002 91. 3913 Ron McFadyen 24
•An Invoice will have a grand total•Each Invoice Line will have a quantity ordered and a subtotal
InvLineamount: Currencyqty_ordered: Quantity
Quantity
amount: Number
InvoiceinvDate: dateamount: Currency
Attributes
Currency
amount: Number
Jan 21, 2002 91. 3913 Ron McFadyen 25
Page 172: No Foreign Keys as attributes in the Domain Model• foreign keys are considered later in design
• example: an Invoice is not shown with an attribute for Customer; that is handled by the association between Customer and Invoice
Invoice
invDate: date
Customer
name: stringaddress: string
Attributes
Jan 21, 2002 91. 3913 Ron McFadyen 26
Page 175: Derived attributes
• the UML notation is to prefix the attribute with a /
SalesLineItem
/quantity/subtotal
Item1..*0, 1
In this case, according to the model, there could be several items related to one line in the sale. These items are all the same type, and the quantity is therefore derivable by counting the number of related items. We are just adding more information to the model.
Attributes
Jan 21, 2002 91. 3913 Ron McFadyen 27
Video
ID
Stocks
Rents
Rents-from
11..*
1 *1*
VideoStore
addressnamephoneNumber
Customer
addressnamephoneNumber
Video store example
Jan 21, 2002 91. 3913 Ron McFadyen 28
VideoRental
dueDatereturnDatereturnTime
CashPayment
amount : Money
Video
ID
Stocks
Rents
Rents-from
Pays-for
Initiates
11
1..*
1
1
1
1..*
1 *1*
RentalTransaction
date1
* *
VideoStore
addressnamephoneNumber
Customer
addressnamephoneNumber
1
Records-rental-of
0..1
1
Video store example
More detail added:
Jan 21, 2002 91. 3913 Ron McFadyen 29
titlesubjectCategory
Video
ID
Specification (Description) conceptual classes
Where do we keep track of the title or other descriptions for things like the videos that are rented?
?
Jan 21, 2002 91. 3913 Ron McFadyen 30
Catalog
VideoDescription
titlesubjectCategory
Video
ID
Stocks
Owns-a
Described-by
1
1
*
1
1
1
* *
1..*
VideoStore
addressnamephoneNumber
1
Specification (Description) conceptual classes
VideoDescription is a class that keeps track of the title and subject category for videos.