♦ Domain model Conceptual classes & attributes Association & multiplicity
Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types:...
Transcript of Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types:...
![Page 1: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/1.jpg)
Domain Models:Associations and AttributesCurt Clifton
Rose-Hulman Institute of Technology
Q1
![Page 2: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/2.jpg)
Description Classes
A description class contains information that describes something else, e.g., ProductDescription
Example…
![Page 3: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/3.jpg)
Consider…
Assume an Item instance represents a physical item in a store
Item data only recorded within Item instances
When a real-world item is solid, we remove the software Item from a collection and it’s garbage collected
description
price
serial number
itemID
Item
Amps that go to 11 are sold out!How much for an Amp
that goes to 11?
![Page 4: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/4.jpg)
Problems
Lose memory of the price, etc., if no Item instances remain in the system
Duplicate data
Wasted space
Error-prone
description
price
serial number
itemID
Item
![Page 5: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/5.jpg)
Solution: Use Description Class
When information must be retained independent of existence of instances of the described item
When deleting the described item could result in info. loss
When it reduces redundant information
![Page 6: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/6.jpg)
Associations
A relationship between classes that indicate some meaningful connection between instances of the classes
Says that we need some memory of the relationship
A memory in the real world, not a software need
Not about data flows, foreign key relationships, instances variables, or software pointers
however transient
Be Parsimonious
Q2
![Page 7: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/7.jpg)
Association Notation
Store ItemStocks
0..1 *
Association name:capitalizetypically camel-case or hyphenateduse verb phraseavoid “has”, “use”
Multiplicity:‘*’ means “many”x..y means from x to y inclusively
Reading direction:typically exclude if association reads left-to-right or top-to-bottom
Q3
![Page 8: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/8.jpg)
Common Association Lists
Association Category POS Examples
A is a transaction related to another transaction B
A is a line item of a transaction B
A is known/logged/recorded in/on B
…
Payment PaysFor Sale
SalesLineItem ContainedIn Sale
Sale CapturedOn Register
…
Q4
![Page 9: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/9.jpg)
Attributes
Include attributes that the requirements suggestneed to be remembered
Notation (square brackets indicate optional parts):
[+|-] [/] name [: [type] [multiplicity]] [= default] [{property}]
firstName
lastName
Person
DerivedVisibility e.g., readOnly
![Page 10: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/10.jpg)
Attribute ExamplesWhat does each part mean?
Q5
![Page 11: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/11.jpg)
Cartoon of the Day
… okay, but because you said that, we’re breaking up.
Related?
http
://x
kcd.
com
/539
/
![Page 12: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/12.jpg)
In Domain Model, Use Data Type Attributes
Primitive data types:
Boolean, String, Real, Integer, …
Sometimes more complex, but not domain specific:
Address, Color, Phone Number, …
If it’s domain specific, use a class and association
Intuition from code: a data type is a primitive type, or a complex type where for
instances a and b,a.equals(b) doesn’t imply a == b Q6
![Page 13: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/13.jpg)
Create Your Own Complex Data Type When
It has attributes of its own
There are operations associated with it (e.g., validation)
It’s a quantity with a unit
![Page 14: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/14.jpg)
Showing Data Type Attributes
Choose the representation that best communicates with the stakeholders
Q7
![Page 15: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/15.jpg)
Example…
Q8
![Page 16: Domain Models: Associations and Attributes · Use Data Type Attributes Primitive data types: Boolean, String, Real, Integer, … Sometimes more complex, but not domain specific:](https://reader034.fdocuments.us/reader034/viewer/2022052008/601cba06e7211a28e73d8ca4/html5/thumbnails/16.jpg)
Domain Model Guidelines, Summarized
Classes first, then associations and attributes
Use existing models, category lists, noun phrases
Include “report objects”, like Receipt, if they’re part of the business rules
Use terms from the domain
Don’t send an attribute to do a conceptual class’s job
Use description classes to remember info. independent of instances and to reduce redundancy
Use association for relationship that must be remembered
Be parsimonious with associations
Name associations with verb phrases, not “has” or “uses”
Use common association lists
Use attributes for information that must be remembered
Use data type attributes
Define new data types for complex data
Communicate with stakeholders