Domain Bacteria Domain Archaea Domain Eukarya Common ancestor Kingdom: Animals Domain Eukarya.
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...
Domain Models
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.
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
How to identify classes?1. Use a conceptual class category list.
2. Linguistic Analysis: identify noun phrases in use cases.
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.
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).
…
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)
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.
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?
Solution: add specification class
Even if all inventoried items are sold and their corresponding Item software
instances are deleted, theProductDescription still remains.
Another Specification Example (Flights)
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)
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
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
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
Multiple associations
Flight Airport
Flies-to
Flies-from
*
* 1
1
• It’s non uncommon to have more than one associations between two classes.
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.
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.
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.
• 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.
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
What about some DM for the airline?