Ooad Unit 2 211230042610
Ooad Unit 2 211230042610
Ooad Unit 2 211230042610
2
Class Diagram (Rumbaugh/Booch)
⚫ Class Diagram Describes
– Types of Objects in Application
– Static Relationships Among Objects
– Temporal Information Not Supported
⚫ Class Diagrams Contain
– Classes: Objects, Attributes, and Operations
– Packages: Groupings of Classes
– Subsystems: Grouping of Classes/Packages
⚫ Main Concepts: Class, Association,
Generalization, Dependency, Realization,
Interface 3
Classes
TariffSchedule
Table zone2price
Enumeration getZones()
Name
Price getPrice(Zone)
TariffSchedule
zone2price Attributes
getZones()
Signature
getPrice()
Operations TariffSchedule
myB.service(); myA.doSomething();
7
Unary Association
8
Aggregation
9
Composition
Composition is Aggregation with:
Lifetime Control (owner controls construction, destruction)
Part object may belong to only one whole object
Employee
Team
-Name : string
-members : Employee +ID : long
1 #Salary : double
-adfaf : bool
*
+getName() : string
+setName()
-calcInternalStuff(in x : byte, in y : decimal)
members[0] =
new Employee();
… Filled diamond on
delete members[0]; side of the Collection
10
Inheritance
Standard concept of inheritance
Base Class
Derived Class
11
Generalization and Associations
*
Item
GroceryOrder
1
Customer NonPItem PerishItem
Supermarket example 12
UML Multiplicities
Multiplicities Meaning
zero or one instance. The notation n . . M
0..1
indicates n to m instances.
no limit on the number of instances
0..* or *
(including none).
1 exactly one instance
1..* at least one instance
13
UML Class Example
14
Supermarket Example in Detail
15
Elaboration
Objectives
⚫ Elaboration is the initial series of
iterations during which the team does the
following
⚫ Serious investigation
⚫ Discover & stabilize major requirements
17
Best Practices
18
Artifacts starting in Elaboration (this will not
be completed rather refined over iterations)
19
You didn’t Understand Elaboration When …
⚫ No Timeboxed schedule
⚫ Single Iteration
⚫ Most requirements already defined
⚫ No Risk mitigation/resolution
⚫ No Executable Architecture
⚫ Requirements Phase
⚫ Attempt full and careful design
20
You didn’t Understand Elaboration When (2)...
21
Domain Model Relationships
Business Model
Domain Model
Classes, attributes, associations
Requirements
Interaction Diagrams
Design
22
A Domain Model
23
Domain Model - UML Notation
24
A Domain Model is not a Software Artifact
25
Identify Conceptual Classes by Noun Phrase:
27
Apply the Mapmaker Strategy
28
A Common Mistake -
Classes as Attributes
30
Description of a Service Example (Flight)
Flight
Date Airport
Flies-to
Time Name
Number vs.
31
The NextGen POS (partial) Domain Model
32
Associations
33
Introduction
34
Associations
association
Records-current
Register Sale
1 1
Fig 1.Associations
35
Useful Associations
36
UML Association Notation
37
UML Association Notation
- “reading direction arrow”
- it has no meaning except to
indicate direction of reading the
association label
- often excluded
Records-current
Register Sale
1 1
38
Finding Associations-Common
Associations List
39
Common Associations List 2
⚫ A is logically contained in B.
Eg:ItemDescription-Catalog.
⚫ A is a description of B. Eg:ItemDescription-
Item.
⚫ A is a line item of a transaction or report B.
Eg:SalesLineItem-Sale.
⚫ A is a member of B. Eg: Cashier-Store.
⚫ A uses or manages B. Eg:Cashier-Register.
40
Common Associations List 3
⚫ A is known/logged/recorded/reported/captured in
B. Eg: Sale-Register.
⚫ A is an organizational subunit of B .
Eg:Department-Store.
⚫ A communicates with B. Eg:Customer-Cashier.
⚫ A is next to B. Eg:City-City.
41
Common Associations List 4
42
High-Priority Associations
43
Associations Guidelines
44
Roles
⚫ multiplicity expression
⚫ navigability
45
Multiplicity
⚫ Multiplicity defines the number of
instances of a class A, that can be
associated with one instance of class B, at
a particular moment.
46
Multiplicity
Stocks
Store Item
1 *
multiplicity of the
role
1..*
T one or more;
1..40
T one to 40
5
T exactly 5
3,5,8
T exactly 3,5 or 8
48
Fig 4. Multiplicity values.
Naming Associations
49
Associations Names
Store
1
Contains
1..*
Register Captures Sale Paid-by Payment
1 1..* 1 1
Airline
1
Employs
1..*
Person Assigned-to Flight Assigned-to Plane
1 * * 1
1 *
Supervises
51
Implementation
53
UML Attribute Notation
SALE Attributes
54
Valid Attribute Types
55
Relate with associations, not attributes
NOT A “SIMPLE”
ATTRIBUTE
CASHIER
Worse
Worse
NAME :
current register
56
Avoid Representing Complex Domain Concepts
as Attributes
DESTINATION IS A
COMPLEX CONCEPT
FLIGHT
Worse
Worse
DESTINATION
1 Flies 1
Better
Better Flight Airport
57
Non Primitive Data Type
58
Non Primitive Data Type
59
Non primitive data Types
60
Attribute box
If the attribute class is a data type, it may be shown in the attribute box
1 1
Product 1 1
ItemID Store Address
Specification
address:
Id: Item ID
Address
61
No attributes as Foreign Key
Worse
Worse
CASHIER
Name:
currentRegisterNumber
Better
Better
1 USES 1 Register
CASHIER
number
NAME
62
Modelling Attribute Quantites and Units
Payment
Not useful
Amount:
Number
* 1
Amount:Number * 1
Amount:Quantity
better
Amount: Money
63
Domain Model Refinement
When to make generalization hierarchies?
Why is the following a good example?
superclass - more general
Payment concept
Guidelines:
• Identify superclasses and subclasses when they help us
understand concepts in more general, abstract terms
and reduce repeated information.
• Expand class hierarchy relevant to the current iteration
and show them in the Domain Model.
64
100% and Is-a rules
Payment
Pays-for Sale
amount : Money 1 1
65
What about this hierarchy?
But useful?
Male Female
Fig. 31.6
Customer Customer
66
Is this hierarchy OK? What does it add to our
understanding of the domain?
Authorizes-payments-of
* Store
*
superclass justified by AuthorizationService
common attributes and
associations address
name additional associations
phoneNumber
Credit Check
Authorization Authorization
Service Service
1 1
Authorizes Authorizes
* *
Credit Check
Payment Payment Fig. 31.8
Models transactions with external services which are important in POS domain 67
When to design Association classes?
a better model, but not
yet as useful as possible
AuthorizationService
Store
Authorizes-payments-via address
address 1..* name
name * phoneNumber
Purchases ServiceContract
Sells
Fig. 31.15
1..* merchantID *
ServiceContract records merchantID—good.
But ServiceContract is dependent on relationship between two classes
AuthorizationService
Store
Authorizes-payments-via address
address 1..* name
name * phoneNumber
an association class
Fig. 31.16 ServiceContract
its attributes are related to the association
merchantID
its lifetime is dependent on the association
68
What about this hierarchy? (Why not?)
Payment
not useful
* Is-in 1
Payment PaymentState better
Unauthorized Authorized
Fig. 31.13 State State
69
More Association classes
Employs
Company * * Person
1 Incarcerates
Jail * Person
JailTerm
dateOfIncarceration
Married-to
Product Product
Catalog 1 1..* Description
Fig. 31.18
71
Higher order package for POS domain
Domain
Authorization
Transactions
Fig.
31.29
What does this higher order package contain?
72
Core/Misc package
Core/Misc
Store
Houses
Register Manager
address 1 1..*
name
1..*
1
Employs
Fig. 31.30
73
Payments
A rich package
1 Authorizes-payments-of
1..*
Paid-by
Check
1
1
Check Credit
CashPayment Credit Check Authorized-by Authorization Authorization
Payment Payment 1
amountTendered
* Service Service
* * * * 1
Authorized-by
Logs
Establishes- Establishes-
credit-for identity-for
Authorization Transactions::
1 1 1
PaymentAuthorizationReply
Accounts CreditCard DriversLicense
Receivable
expiryDate number
number - CheckPayments have
1
Identifies CheckPaymentReplies
1 1
Abused-by - CreditPayments have
Sales::Customer
1 CreditPaymentReplies
Fig. 31.31
74
Note: Composition and tie to Core package
Products
Sales::
SalesLineItem 0..1
Described-by *
1
Product
Description
ProductCatalog description
1 1..*
price
itemID
1
Records-sale-of
Describes
*
Core:: Stocks Item
Store 1 1
*
Fig. 31.32 75
Iteration-3 of Monopoly domain model
76
Conceptual Class Hierarchies
● Organizing classes into hierarchies facilitates
the reuse of code and the reuse of solutions
to design problems that have already been
solved.
● Class hierarchies as sets - supersets
(referred to as superclasses or base classes),
and subsets (referred to as subclasses or
derived classes).
Conceptual Class Category
Conceptual Class Category Examples
Physical or tangible objects Register, Airplane
Specifications, deigns or descriptions of ProductSpecification, FlightDescription
things
Places Store, Airport
Transactions Sale, Payment, Reservation
Transaction line items SalesLineItem
Roles of people Cashier, Pilot
Containers of other things Store, Bin, Airplane
Things in a container Item, Passenger
Other computer or electro-mechanical CreditPaymentAuthorizationSystem
systems external to the system AirTrafficControl
Organizations SalesDepartment, ObjectAirline
Events Sale, Payment, Meeting, Flight, Crash,
Landing
Rules and policies RefundPolicy
CancellationPolicy
Catalogs ProductCatalog, PartsCatalog
Records of finance, work, contracts, Receipt, Ledger, EmploymentContract,
legal matters MaintenanceLog
Financial instruments and services LineOfCredit, Stock
Manuals, documents, reference papers, DailyPriceChangeList , RepairManual
books
Example:
Design of Class Hierarchies
⚫ Design a system of classes, put common
data and functionality in a superclass,
which you then use to derive subclasses.
⚫ The subclasses inherit the data and
functionality of the superclass and define
only aspects that are unique to their
particular purposes.
Class Hierarchies advantages:
⚫ Avoid duplicating code that is common to
all classes.
⚫ Add or change subclasses at any time
without modifying the superclass or
affecting other subclasses.
⚫ If the superclass changes (for example,
all employees are assigned a number),
then subclass automatically get these
changes.
Aggregation and Composition
: Cashier :System
makeNewSale