chapter 9

39
Chapter 9 Domain Models The classic OOAD model

Upload: dotty

Post on 10-Jan-2016

39 views

Category:

Documents


2 download

DESCRIPTION

Chapter 9. Domain Models The classic OOAD model. Fig. 9.1. Domain Model. Representation of real-situation conceptual classes Not software objects! Model: Domain objects (conceptual classes) Associations Attributes of conceptual classes. Things not in a Domain Model. Software artifacts - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Chapter 9

Chapter 9

Domain Models

The classic OOAD model

Page 2: Chapter 9

Fig. 9.1

Process Sale

1. Customer arrives ...2. ...3. Cashier enters item identifier.4....

Use Case Text

Operation: enterItem(…)

Post-conditions:- . . .

Operation Contracts

Sale

date. . .

SalesLineItem

quantity

1..*1 . . .

. . .

the domain objects, attributes, and associations that undergo state changes

Domain Model

Use-Case Model

Design Model

: Register

enterItem(itemID, quantity)

: ProductCatalog

spec = getProductSpec( itemID )

addLineItem( spec, quantity )

: Sale

. . .

conceptual classes in the domain inspire the names of some software classes in the design

conceptual classes –terms, concepts attributes, associations

Cashier: …Item ID: …...

Glossary

elaboration of some terms in the domain model

Require-ments

Business Modeling

Design

Sample UP Artifact Relationships

Page 3: Chapter 9

Domain Model

• Representation of real-situation conceptual classes

• Not software objects!

• Model:– Domain objects (conceptual classes)– Associations– Attributes of conceptual classes

Page 4: Chapter 9

Things not in a Domain Model

• Software artifacts• Responsibilities or methods• Data Model

Page 5: Chapter 9

Fig. 9.2

Register

Item

Store

addressname

Sale

date time

Payment

amount

SalesLineItem

quantity

Stocked-in

*

Houses

1..*

Contained-in

1..*

Records-sale-of

0..1

Paid-by

1

1

1

1

1

1

0..1

1

Captured-on

conceptor domain object

association

attributes

Page 6: Chapter 9

Fig. 9.3

Sale

dateTime

visualization of a real-world concept in the domain of interest

it is a not a picture of a software class

Page 7: Chapter 9

Fig. 9.4

SalesDatabase software artifact; not part of domain model

software class; not part of domain model

Sale

datetime

print()

Page 8: Chapter 9

Fig. 9.5

Sale

datetime

concept's symbol

"A sale represents the event of a purchase transaction. It has a date and time."

concept's intension

sale-1

sale-3sale-2

sale-4

concept's extension

Page 9: Chapter 9

Why?

• Understand key concepts of domain– Key concepts– Vocabulary

• Lower the gap between representations

Page 10: Chapter 9

Fig. 9.6Payment

amount

Sale

datetime

Pays-for

Payment

amount: Money

getBalance(): Money

Sale

date: DatestartTime: Time

getTotal(): Money. . .

Pays-for

UP Domain ModelStakeholder's view of the noteworthy concepts in the domain.

UP Design ModelThe object-oriented developer has taken inspiration from the real world domain in creating software classes.

Therefore, the representational gap between how stakeholders conceive the domain, and its representation in software, has been lowered.

1 1

1 1

A Payment in the Domain Model is a concept, but a Payment in the Design Model is a software class. They are not the same thing, but the former inspired the naming and definition of the latter.

This reduces the representational gap.

This is one of the big ideas in object technology.

inspires objects

and names in

Page 11: Chapter 9

How?

• Reuse an existing model– Easier– Less error prone– Many problems are not new

• Category list– Text has a table of common categories (table 9.1)

• Noun phrases– Use with care!

Page 12: Chapter 9

Examples using concept list

• Fig 9.7 is POS domain• Fig 9.8 is Monopoly

Page 13: Chapter 9

Fig. 9.7

StoreRegister SaleItem

CashPayment

SalesLineItem

Cashier Customer

ProductCatalog

ProductDescription

Ledger

Page 14: Chapter 9

Fig. 9.8

Page 15: Chapter 9

Guidelines

• Report objects• Think like a mapmaker• Modeling the unreal world• Attributes vs. classes• Description classes

Page 16: Chapter 9

Fig. 9.9

Item

descriptionpriceserial numberitemID

ProductDescription

descriptionpriceitemID

Item

serial number

Describes Better

Worse

1 *

Page 17: Chapter 9

Fig. 9.10Worse

Flight

datetime

FlightDescription

number

Airport

name

Describes-flights-to

Described-by

Flight

datenumbertime

Airport

name

Flies-to

Better

1*

1*

1

*

Page 18: Chapter 9

Associations

• Things that need to be remembered• Use with care• May or may not be implemented in

software• Naming:

– className-verbPhrase-className

Page 19: Chapter 9

Fig. 9.11

SaleRegisterRecords-current

1 1

association

Page 20: Chapter 9

Fig. 9.12

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 21: Chapter 9

Fig. 9.13

ItemStore Stocks

*

multiplicity of the role

1

Page 22: Chapter 9

Fig. 9.14zero or more; "many"

one or more

one to 40

exactly 5

T

T

T

T

*

1..*

1..40

5

T3, 5, 8

exactly 3, 5, or 8

Page 23: Chapter 9

Fig. 9.15

ItemStore Stocks 1

or 0..1

Multiplicity should "1" or "0..1"?

The answer depends on our interest in using the model. Typically and practically, the muliplicity communicates a domain constraint that we care about being able to check in software, if this relationship was implemented or reflected in software objects or a database. For example, a particular item may become sold or discarded, and thus no longer stocked in the store. From this viewpoint, "0..1" is logical, but ...

Do we care about that viewpoint? If this relationship was implemented in software, we would probably want to ensure that an Item software instance would always be related to 1 particular Store instance, otherwise it indicates a fault or corruption in the software elements or data.

This partial domain model does not represent software objects, but the multiplicities record constraints whose practical value is usually related to our interest in building software or databases (that reflect our real-world domain) with validity checks. From this viewpoint, "1" may be the desired value.

*

Page 24: Chapter 9

Fig. 9.16

Flight Airport

Flies-to

Flies-from

*

* 1

1

Page 25: Chapter 9

Fig. 9.17

Register

ItemStore

Sale

CashPayment

SalesLineItem

CashierCustomer

ProductCatalog

ProductDescription

Stocks

*

Houses

1..*

Used-by

*

Contains

1..*

Describes

*

Captured-on

Contained-in

1..*

Records-sale-of

0..1

Paid-by Is-for

Logs-completed

*

Works-on

1

1

1

1 1..*

1

1

1

1

1

1

1

0..1 1

1

Ledger

Records-accounts-

for

1

1

Page 26: Chapter 9

Fig. 9.18

Page 27: Chapter 9

Attributes

• Information that needs to be remembered

Page 28: Chapter 9

Fig. 9.19

Sale

dateTime/ total : Money

attributes

derived attribute

Page 29: Chapter 9

Fig. 9.20

Sale

- dateTime : Date- / total : Money

Private visibility attributes

Math

+ pi : Real = 3.14 {readOnly}

Public visibility readonly attribute with initialization

Person

firstNamemiddleName : [0..1]lastName

Optional value

Page 30: Chapter 9

Fig. 9.21

SalesLineItem ItemRecords-sale-of 10..1

SalesLineItem ItemRecords-sale-of 0..1 1..*

Each line item records a separate item sale.For example, 1 tofu package.

Each line item can record a group of the same kind of items.For example, 6 tofu packages.

SalesLineItem

/quantity

ItemRecords-sale-of 0..1 1..*

derived attribute from the multiplicity value

Page 31: Chapter 9

Fig. 9.22

Cashier

namecurrentRegister

Cashier

name

Register

number

Uses

Worse

Better

not a "data type" attribute

1 1

Page 32: Chapter 9

Fig. 9.23

Flight

Flight

destinationWorse

BetterFlies-to Airport1 1

destination is a complex concept

Page 33: Chapter 9

Datatypes

• Use simple types• Define complex types where needed

– Subparts– Needs operations– Has attributes (e.g. start date)– Units– Polymorphic types

Page 34: Chapter 9

Fig. 9.24

OK

OK

ProductDescription

ProductDescription

itemId : ItemID

1Store

Store

address : Address

11 1

ItemID

idmanufacturerCodecountryCode

Address

street1street2cityName...

Page 35: Chapter 9

Fig. 9.25

Cashier

namecurrentRegisterNumber

Cashier

name

Register

number

Works-on

Worse

Better

a "simple" attribute, but being used as a foreign key to relate to another object

1 1

Page 36: Chapter 9

Fig. 9.26

Payment

amount : Number

Payment Quantity

amount : Number

Unit

...

Payment

amount : Quantity

Has-amount1*

Is-in1*

not useful

quantities are pure data values, so are suitable to show in attribute section better

Payment

amount : Money

variation: Money is a specialized Quantity whose unit is a currency

Page 37: Chapter 9

Fig. 9.27

Register

id

ItemStore

nameaddress

Sale

dateTime/ total

CashPayment

amountTendered

SalesLineItem

quantity

Cashier

id

Customer

ProductCatalog

ProductDescription

itemIDdescriptionprice

Stocks

*

Houses

1..*

Used-by

*

Contains

1..*

Describes

*

Captured-on

Contained-in

1..*

Records-sale-of

0..1

Paid-by Is-for

Logs-completed

*

Works-on

1

1

1

1 1..*

1

1

1

1

1

1

1

0..1 1

1

Ledger

Records-accounts-

for

1

1

Page 38: Chapter 9

Fig. 9.28

Page 39: Chapter 9

Summary – Domain Models

• A domain model is used to understand the domain

• It is an artifact that is developed iteratively in Agile