domain model—part 3: associations, multiplicity and attribute- text notation

21
Domain Model—Part 3: Associations, Multiplicity and Attribute-Text Notation

Upload: noel-ellis

Post on 04-Jan-2016

225 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

Domain Model—Part 3:

Associations, Multiplicity and Attribute-Text Notation

Page 2: 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

Page 3: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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.

Page 4: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

“Need to remember” “Preserved for some duration” Common Associations List (p.155)

“patterns” – e.g. Sale to SaleLineItem to Item.

Page 5: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

Multiplicity defines how many instances of class A can be associated with one instance of class B

Page 6: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

Name Multiplicity (of Roles) Multiple Associations NOTE: Multiplicity depends on time

Examples p.157

CourseSectionInstructor

0..n1 0..n1

Teaches

Page 7: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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

Page 8: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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

Page 9: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

In the domain Model Relate conceptual classes with an association,

NOT an attribute Cashier to Register NOT currentRegister attribute of Cashier

Page 10: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

Cashier

namecurrentRegister

Cashier

name

Register

number

Uses

Worse

Better

not a "data type" attribute

1 1

Page 11: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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.

Page 12: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation
Page 13: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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

Page 14: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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

Page 15: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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;

Page 16: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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

Page 17: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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.

Page 18: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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.

Page 19: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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

Page 20: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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.

Page 21: Domain Model—Part 3: Associations, Multiplicity and Attribute- Text Notation

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