Chapter 9
-
Upload
whitney-golden -
Category
Documents
-
view
35 -
download
0
description
Transcript of Chapter 9
![Page 1: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/1.jpg)
Chapter 9
Domain Models
1CS6359 Fall 2012 John Cole
![Page 2: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/2.jpg)
Why do this?
• If you don’t understand the domain, you can’t program for it effectively
• Lower the representational gap between mental model and software model
CS6359 Fall 2012 John Cole 2
![Page 3: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/3.jpg)
Objectives
• Identify conceptual classes related to the current iteration
• Create an initial domain model• Model appropriate attributes and associations
CS6359 Fall 2012 John Cole 3
![Page 4: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/4.jpg)
What is a Domain Model?
• Illustrates noteworthy concepts in a domain. That is, defines what the system is about
• Models the things in your system and the way they relate to each other
• A domain model is conceptual, not a software artifact
• A visual dictionary
CS6359 Fall 2012 John Cole 4
![Page 5: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/5.jpg)
What’s the Difference?
CS6359 Fall 2012 John Cole 5
Conceptual Class:
SaleSale
amtamt
itemitem
Software Artifacts:
SalesDatabaseSalesDatabase
SaleSale
Double amt;Double amt;
Item item;Item item;
void print()void print()
![Page 6: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/6.jpg)
Business Object Model
• Class diagrams with no methods, just fields• May show domain objects • Associations between classes• Attributes of conceptual classes
CS6359 Fall 2012 John Cole 6
![Page 7: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/7.jpg)
Domain Model, visually
CS6359 Fall 2012 John Cole 7
![Page 8: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/8.jpg)
Conceptual Classes
• An idea, thing, or object• Symbol—Words or images representing a
conceptual class• Intension—Definition of a conceptual class• Extension—The set of examples to which the
class applies• It is not a data model
CS6359 Fall 2012 John Cole 8
![Page 9: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/9.jpg)
How to Create a Domain Model
• Find the conceptual classes• Draw them as classes in a UML class diagram• Add associations necessary to record
relationships• Add attributes necessary for information to be
preserved• Use existing names, the vocabulary of the
domain
CS6359 Fall 2012 John Cole 9
![Page 10: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/10.jpg)
How do I find Conceptual Classes?
• Reuse or modify existing models. If there are published models, prior art, or books, use them
• Use a category list (Table 9.1)• Identify noun phrases (linguistic analysis)
CS6359 Fall 2012 John Cole 10
![Page 11: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/11.jpg)
Noun Phrase Identification
CS6359 Fall 2012 John Cole 11
• Consider the following problem description, analyzed for Subjects, Verbs, Objects:
The ATM verifies whether the customer's card number and PIN are correct. S V O O OIf it is, then the customer can check the account balance, deposit cash, and withdraw cash. S V O V O V O Checking the balance simply displays the account balance. S O V ODepositing asks the customer to enter the amount, then updates the account balance. S V O V O V O Withdraw cash asks the customer for the amount to withdraw; if the account has enough cash, S O V O O V S V Othe account balance is updated. The ATM prints the customer’s account balance on a receipt. O V S V O O
![Page 12: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/12.jpg)
Noun Phrases
Analyze each subject and object as follows:• Does it represent a person performing an action?
Then it’s an actor, ‘R’.• Is it also a verb (such as ‘deposit’)? Then it may be a
method, ‘M’.• Is it a simple value, such as ‘color’ (string) or ‘money’
(number)?Then it is probably an attribute, ‘A’.
• Which NPs are unmarked? Make it ‘C’ for class. Verbs can also be classes, for example:• Deposit is a class if it retains state information
CS6359 Fall 2012 John Cole 12
![Page 13: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/13.jpg)
Where are the Terms?
• Some are in the use case• Some come from domain experts• Natural language is imprecise and ambiguous,
so you need to use judgment
CS6359 Fall 2012 John Cole 13
![Page 14: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/14.jpg)
POS example
CS6359 Fall 2012 John Cole 14
You can create a list, or you can use a set of class diagrams, per the table below
StoreRegister SaleItem
Payment
SalesLineItem
Cashier Customer Manager
ProductCatalog
ProductSpecification
![Page 15: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/15.jpg)
Monopoly Game Domain Model
CS6359 Fall 2012 John Cole 15
![Page 16: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/16.jpg)
Maintaining the Model
• Usually the model is a guideline to thinking, not an end in itself. Thus it will change as you learn more
• Who will use the updated model?
CS6359 Fall 2012 John Cole 16
![Page 17: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/17.jpg)
Report Objects
• Including reports in a domain model usually isn’t useful because the information is derived from other objects.
• There are special cases, such as receipts, that should be in the model.
CS6359 Fall 2012 John Cole 17
![Page 18: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/18.jpg)
Mapmaker (domain terms) Strategy
• Use existing names so far as possible. Learn the terms your users use.
• Exclude out-of-scope features. If a feature is not in the current iteration, don’t use it.
• Model the “unreal” world (i. e. Telecom) by listening carefully to the vocabulary of experts. “Port” means two different things in telecom and shipping.
CS6359 Fall 2012 John Cole 18
![Page 19: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/19.jpg)
Attributes vs. Classes
• Common mistake: representing something as an attribute when it should have been a class.
• “If we do not think of some conceptual class X as a number or text in the real world, it should probably be a class, not an attribute.”
• Should “store” be an attribute of Sale or should it be a class?
CS6359 Fall 2012 John Cole 19
![Page 20: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/20.jpg)
Description Classes
• A description class contains information that describes something else
• E. g. Product Description records the price, picture, text description (and what else?) of an item
CS6359 Fall 2012 John Cole 20
![Page 21: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/21.jpg)
Why Use Them?
• If we keep all the information in, say, a sales line item, once all of that item are sold, there is no record of what the item was
• How does this relate to database design?
CS6359 Fall 2012 John Cole 21
![Page 22: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/22.jpg)
Associations
• Relationship between (instances of) classes that indicates some interesting and meaningful connection
• What objects need memory of a relationship?• In Monopoly, where each piece is and which
player owns which token• No need to remember numbers on the dice
CS6359 Fall 2012 John Cole 22
![Page 23: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/23.jpg)
Associations (cont’d)
• Avoid having too many; this adds communication paths and complexity
• Will they be implemented in software?• UML: Line between classes with the name of
the association• Name with VerbPhrase-ClassName format. E.
g. Sale Paid By CashPayment• Each end of an association is called a Role
CS6359 Fall 2012 John Cole 23
![Page 24: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/24.jpg)
Associations (cont’d)
• Multiplicity: how many instances of class A can be associated with an instance of class B.
• E. g. an instance of Store can be associated with many (zero or more) Items
• This is at a particular moment, not over time• Discussion of 0..1 or 1• Multiple associations: Flight FliesTo and FliesFrom an
airport• Common Associations List on p. 155
CS6359 Fall 2012 John Cole 24
![Page 25: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/25.jpg)
Attributes• An Attribute is a logical data value of an object• You can also have derived attributes denoted
by / before the name• Full syntax: visibility Name : type multiplicity =
default {property string}• +pi : Real=3.14159 {read-only}
CS6359 Fall 2012 John Cole 25
Sale
datestartTime : Time
attributes
![Page 26: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/26.jpg)
Attribute Types
• Usually primitive data types, as well as things like Color, DateTime, Zip code, etc. The latter are specializations of primitive types
• It should not normally be a class, such as Sale or Airport
• Relate conceptual classes with an association, not an attribute. No foreign keys
• Attributes in code are okay
CS6359 Fall 2012 John Cole 26
![Page 27: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/27.jpg)
New Data Type Classes
• Things like ItemID or ClaimNumber are not always simple data types, even though they look like them
• If the attribute contains separable pieces, it can be its own class. For example, a Claim Number has the state, year, and day encoded in it
• If it has operations associated with it
CS6359 Fall 2012 John Cole 27
![Page 28: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/28.jpg)
New Data Type Classes (cont’d)
• If it has other attributes, such as a sale price• If it has units, such as currency• If it is an abstraction of one or more types
with these properties
CS6359 Fall 2012 John Cole 28
![Page 29: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/29.jpg)
Quantities with Units
• Represent them with distinct classes with an associated unit
CS6359 Fall 2012 John Cole 29
Payment
amount : Number
Payment Quantity
amount : Number
Unit
...
Payment
amount : Quantity
Has-amount1*
Is-in1*
not useful
quantities are pure datavalues, so suitable to showin attribute section better
Payment
amount : Money
variation: Money is aspecialized Quantity whoseunit is a currency
![Page 30: Chapter 9](https://reader033.fdocuments.in/reader033/viewer/2022051516/5681351b550346895d9c760a/html5/thumbnails/30.jpg)
Is the Domain Model Correct?
• No, but it’s a good approximation• It gets better with each iteration; don’t try to
get it all at once• Domain model usually done in the elaboration
phase
CS6359 Fall 2012 John Cole 30