Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation.
-
Upload
noel-ellis -
Category
Documents
-
view
221 -
download
1
Transcript of Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation.
Domain Model—Part 3:
Associations, Multiplicity and Attribute-Text Notation
“a relationship between instances of classes (objects) that indicates some meaningful and interesting connection” (text, p. 150)
Ins tructor CourseSectionteaches
When “memory” of a relationship is required (in a real world situation, not a software
situation) SalesLineItem instances are associated with a
Sale instance. Otherwise, it would not be possible to reconstruct a sale, print a receipt, or calculate a sale total.
“Need to remember” “Preserved for some duration” Common Associations List (p.155)
“patterns” – e.g. Sale to SaleLineItem to Item.
Multiplicity defines how many instances of class A can be associated with one instance of class B
Name Multiplicity (of Roles) Multiple Associations NOTE: Multiplicity depends on time
Examples p.157
CourseSectionInstructor
0..n1 0..n1
Teaches
SaleRegister Records-current 0..11
association name multiplicity
-"reading direction arrow"-it has no meaning except to indicate direction of reading the association label-often excluded
If we are selling a quantity of n of the same product (product:Product) then the SaleLine is associated with quantity n of that Product. But it is only associated with 1 Product.
Note: this is sometimes modeled as a many to many association in a conceptual domain model to refer to the fact that a sale line can refer to many of the same product (e.g. 4 green peppers) BUT we are beyond that—as soon as we specify that product refers to an instance of the Product class, the multiplicity on the Product end should be a 1.
Sale
saleNumberdatesaleLineSet : SaleLine
SaleLine
product : Productquantity
1..*
1
1..*
1
Product
prodNumber
10..*0..* 1
Sells quantity of
Contains
A good association name helps clarify the association
In the domain Model Relate conceptual classes with an association,
NOT an attribute Cashier to Register NOT currentRegister attribute of Cashier
Cashier
namecurrentRegister
Cashier
name
Register
number
Uses
Worse
Better
not a "data type" attribute
1 1
Attributes are shown several ways: attribute text notation, such as currentSale :
Sale. association line notation both together
Figure 16.3 shows these notations being used to indicate that a Register object has an attribute (a reference to) one Sale object.
NOTE: the information that follows is only for the purposes of answering the question “when would we use directional associations?” Directional associations have arrows; regular
associations do not
Directional associations are typically part of a Design Model (further on in the domain/design process); we would not usually show this in a domain model. (Larman, p.253)
What this means:• Order “knows” about OrderLine; OrderLine does not “know” about Order. In code, each Order class contains a reference to OrderLine objects (productOrderedSet). The OrderLine objects do not contain a reference to OrderLine.
OrderLine
product : Productquantity
1..*
contains
1
Order
orderIDcustomer : CustomerproductOrderedSet : OrderLine
Address
streetNumstreetNamecitypostcodeprovincecountry
Customer
custIDcustNamecustAddress : AddresscontactSet : ContactisInactive
1
1
1
1operates at
Contact
contactIDcontactNamecontactPhone
1..*
1
1..*
1
can be reached by calling
public class Customer {private int custID;private String custName;private Address address;private List<Contact> contactSet;private Boolean isActive;
public class Address {private int streetNum;private String streetName;private String city;private String postCode;private String province;private String country;
public class Contact {private int contactID;private String name;private String phone;
A data type refers to objects for which unique identity is not important.
Common data types are primitive-oriented types such as: Boolean, Date (or DateTime), Number,
Character, String (Text), Time, Address, Color, Geometrics (Point, Rectangle), Phone Number, Social Security Number, Universal Product Code (UPC), SKU, ZIP or postal codes, enumerated types
Sale
saleNumberdatesaleLineSet : SaleLine
SaleLine
product : Productquantity
1..*
1
1..*
1
Product
prodNumber
10..*0..* 1
Showing objects as attributes is typically reserved for the Design model (further on in the analysis and design process) but we are showing them here in SYS466 to aid in understanding.
Sale
saleNumberdatesaleLineSet : SaleLine
SaleLine
product : Productquantity
1..*
1
1..*
1
Product
prodNumber
10..*0..* 1
In OO language implementation, objects will contain references to their object attributes. For example SaleLine will contain a reference to a Product object.
public class Order {
private int orderID;private Customer customer;private List<OrderLine>
productOrderedSet;
public class OrderLine {
private int qtyOrdered;private Product product;
public class Product {
private int productID;private String productName;
Product
productIDproductName
OrderLine
product : ProductqtyOrdered
1
1..*
1
1..*
orders
1..*
1
1..*
Order
orderIDcustomer : CustomerproductOrderedSet : OrderLine
orders quantity of
contains
Guideline: Use the attribute text notation for data type objects and the association line notation for others. Both are semantically equal, but showing an association line to another class in the diagram (as in Figure 16.3) gives visual emphasis—it catches the eye, emphasizing the connection between the class of objects on the diagram.
Slide material was taken fromApplying UML and Patterns: An
Introduction to Object-Oriented Analysis and Design and Iterative Development, Third Edition, By Craig Larman, Published by Prentice Hall, Pub. Date: October 20, 2004. Chapter 16