Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model...
Transcript of Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model...
![Page 1: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/1.jpg)
Domain Models
![Page 2: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/2.jpg)
About Domain Models1. Domain model is the most important—and classic—
model in OO analysis.2. Illustrates noteworthy concepts in a problem
domain. 3. Acts as a source of inspiration for software objects.
Value of OOA/D knowledge over UML notation; – Basic notation is trivial, but there are subtle modeling
guidelines for a useful model.– Will explore basic skills in creating domain models.
![Page 3: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/3.jpg)
Domain Model• Key idea: Domain Model – A visual dictionary of
abstractions about the real world.• Class diagrams with no operations specified. • Attributes and relationships YES.• Conceptual classes: idea, thing, or object. • Classes don’t necessarily correspond to software
classes.
Store Register Sale
![Page 4: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/4.jpg)
![Page 5: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/5.jpg)
How to identify classes?1. Use a conceptual class category list.
2. Linguistic Analysis: identify noun phrases in use cases.
![Page 6: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/6.jpg)
Conceptual Class Category List• Physical or tangible objects
– Register, Airplane• Specifications, or descriptions of things
– ProductSpecification, FlightDescription• Places
– Store, Airport• Transactions
– Sale, Payment, Reservation• Transaction items
– SalesLineItem• Roles of people
– Cashier, Pilot• Containers of other things
– Store, Hangar, Airplane• Things in a container
– Item, Passenger• Computer or electro-mechanical systems
– CreditPaymentAuthorizationSystem, AirTrafficControl• Catalogs
– ProductCatalog, PartsCatalog• Organizations
– SalesDepartment, Airline
Same category list applies to
many problems.
![Page 7: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/7.jpg)
Finding noun phrases in use casesMain Success Scenario (or Basic Flow):1. Customer arrives at POS checkout with goods and/or services to
purchase.2. Cashier starts a new sale.3. Cashier enters item identifier.4. System records sale line item and presents item description, price,
and running total. Price calculated from a set of price rules.5. System presents total with taxes calculated.
6. Cashier tells Customer the total, and asks for payment.7. Customer pays and System handles payment.8. System logs completed sale and sends sale and payment
information to the external Accounting system (for accounting and commissions) and Inventory system (to update inventory).
…
![Page 8: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/8.jpg)
Candidate Conceptual Classes
• Register (cat list)• Item (noun)• Store (cat list)• Sale (noun)• Payment (noun)• ProductCatalog (cat list)
• ProdSpecification (cat list)
• SaleLineItem (noun)• Cashier (noun)• Customer (noun)
![Page 9: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/9.jpg)
Attribute or class?If we don’t think of some conceptual class X as a number or string, then X is probably a class, not an attribute.
![Page 10: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/10.jpg)
Need for specification classes• E.g.
– An Item instance represents a physical item in a store.– An Item has a description, price, and itemID, which aren’t
recorded anywhere else.– Everyone in store has amnesia.– Every time a real physical item is sold, an Item is deleted.
• What can go wrong?1. When some product is all sold out there is no info
anymore about it.2. The data about price and description is replicated at each
item. • This brings update anomalies. Why?
![Page 11: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/11.jpg)
Solution: add specification class
Even if all inventoried items are sold and their corresponding Item software
instances are deleted, theProductDescription still remains.
![Page 12: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/12.jpg)
Another Specification Example (Flights)
![Page 13: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/13.jpg)
Associations• Associations record relationships for which there
is a need to preserve some memory. Usually when: – A is subpart/member of B. (SaleLineItem - Sale)– A uses or manages B. (Cashier – Register, Pilot-
airplane)– A communicates with B. (Student - Teacher)– A is transaction related to B. (Payment - Sale)– A is next to B. (SaleLineItem - SaleLineItem)– A is owned by B. (Plane-Airline)– A is an event related to B. (Sale-Store)
![Page 14: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/14.jpg)
Roles and Multiplicity• Each end of an association is called a role.
• Multiplicity defines how many instances of a class A can be associated with one instance of class B.
• E.g., a single instance of a Store can be associated with “many” (zero or more) Item instances.
ItemStore Stocks
*
multiplicity of the role
1
![Page 15: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/15.jpg)
Some examples of multiplicityzero or more;"many"T*
one or moreT1..*
one to 40T1..40
exactly 5T5
T3, 5, 8
exactly 3, 5, or 8
![Page 16: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/16.jpg)
POS Domain Model
Register
Item
Store
addressname
Sale
datetime
Payment
amount
LineItem
quantity
Stocked-in
*
Houses
1..*
Contained-in
1..*
Records-sale-of
0..1
Paid-by
1
1
1
1
1
1
1
1
Captured-on 4
![Page 17: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/17.jpg)
Multiple associations
Flight Airport
Flies-to
Flies-from
*
* 1
1
• It’s non uncommon to have more than one associations between two classes.
![Page 18: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/18.jpg)
Attributes vs. Associations
Cashier
namecurrentRegister
Cashier
name
Register
numberUses
Worse
Better
not a "simple" attribute
1 1
• Relate conceptual classes with an association, not with an attribute.
![Page 19: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/19.jpg)
Conceptual vs. Implementation• How the associations are implemented in Java or
C++?• Very often by references or pointers, which are
attributes of the software classes. • This is a source of confusion…but they are
conceptually different. • So, we keep the associations distinct from
attributes in the Domain Model.
![Page 20: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/20.jpg)
In practice…keep the implementation in mind
• Suppose you have two Personobjects, o1 and o2 whose names are “Jill Smith.”
• These people are different, and so are the memory addresses (refs) of o1 and o2.
• Thus, when comparing we do so with respect to memory addresses and we are Ok.
• Now, suppose you want to compare the phone numbers of two people.
• You care about the values, not about their memory address!
• The same for name, address, etc.
Bottom lineAttributes are data values.Associations are refs.
![Page 21: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/21.jpg)
• What about values that can get too complex, like address?
• The choice is yours, with a slight preference for creating separate classes for them.
• Also, no attributes as foreign keys.
![Page 22: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/22.jpg)
Register
ItemStore
addressname
Sale
date
time
Payment
amount
SalesLineItem
quantity
CashierCustomer
Manager
ProductCatalog
ProductSpecification
descriptionpriceitemID
Stocks
*
Houses
1..*
Used-by
*
Contains1..*
Describes
*
Captured-on
Contained-in
1..*
Described-by
*
Records-sale-of
0..1
Started-by
Paid-by Initiated-by
Logs-completed6
*
3 Records-sales-on
1
1
1
1
1
1..*
11
1
1
1
1
1
1
1
1 1
1
![Page 23: Domain Models - UVic.cawebhome.cs.uvic.ca/~thomo/seng330/ch_9.pdfAbout Domain Models 1. Domain model is the most important—and classic— model in OO analysis. 2. Illustrates noteworthy](https://reader033.fdocuments.in/reader033/viewer/2022060421/5f17b74b6f61204b6f4299d8/html5/thumbnails/23.jpg)
What about some DM for the airline?