Title: Lesson 4' More on Class Diagram
1Lesson 4.More on Class Diagram
2Contents
- Stereotypes
- Multiple Classification
- Aggregation and Composition
- Interfaces and Abstract Class
- Qualified Association
- Association Class
- Parameterized Class
3Stereotypes
- Definition
- A high-level classification of an object
- A stereotype indicates what kind of object(class)
it is. - Stereotypes of classes, relations, or
generalizations - Examples
- Controller and Coordinator
- Interface Class, Control Class, Entity Class
- Notation
ltltPurchase Ordergtgt
UML notation for Stereotype Object
4Multiple Classification
- Definition
- An object may be described by several types that
are not necessarily connected by inheritance. - Multiple types of an Object
- Different from multiple inheritance
- Discriminator
- An indication of the basis of the subtyping
- Make it clear which combinations are legal
- It can be marked as complete, meaning that any
instance of the superclass must be an instance of
one of the subclass in that group.
5Multiple Classification
Surgeon
discriminator
Doctor
Female
Family Doctor
role
Person
Nurse
sex complete
Male
Physio- therapist
patient
Patient
- Legal combination
- (Female, Patient, Nurse)
- (Male, Physiotherapist)
- (Female, Patient)
- (Female, Doctor, Surgeon)
- Illegal combination
- (Patient, Doctor)
- (Male, Doctor, Nurse)
6Dynamic Classification
- Definition
- Objects can change type within the subtyping
structure - Static classification does not allow the type
change of objects
Manager
Female
job ltltdynamicgtgt
Person
Engineer
sex complete
Male
Saleman
7Aggregation and Composition
- Aggregation
- Aggregation is the part of relationship.
- Different with association
- Composition
- A stronger variety of aggregation
- The part object may belong to only one whole
object. - The part objects are usually expected to live and
die with the whole object. - Orderlines are deleted when the Order is deleted.
8Aggregation and Composition
Polygon
Composition
Aggregation
1
1
1
Graphics Bundle
ordered
3..
Point
Color Texture
9Interface and Abstract Class
- Interface(as in Java)
- A class with no implementation
- Has function declarations but no method bodies.
- Primarily used to declare an interface.
- Abstract Class(as in Java and C)
- Allows implementation of some of the methods
- Syntax
- Use a stereotype, ltltinterfacegtgt
- Use a constraint, abstract
10Interface and Abstract Class
Windows Window
- Example of Abstract Class
toFont() toBack()
Window abstract
X11 Window
Text Editor
toFont() toBack()
toFont() toBack()
Mac Window
toFont() toBack()
11Interface and Abstract Class
InputStream abstract
ltltinterfacegtgt DataInput
OrderReader
Generalization
DataInputStream
Refinement
12Qualified Associations
- Definition
- Argument(or identity) required to access the
objects of the class in an association - UML equivalent of associative arrays and
dictionaries. - Example
One order line for each instance of Product
OrderLine
Order
0..
Product
amount Number
line item
class Order public Orderline
lineItem(Product aProduct) public void
addLineItem(Number amount, Product
forProduct)
13Association Class
- Definition
- An association class has attributes and operation
for the given association.
Person
Company
employer
0..1
Association Class
Employment
peroiddateRange
14Parameterized Class
- C template
- class SetltTgt
- void insert (T newElement)
- void remove(T newElement)
-
-
- Set ltEmployeegt employeeSet
Template Parameter
T
Set
ltltbindgtgt
EmployeeSet
ltEmployeegt
insert(T) remove(T)
Template Class
Set ltEmployeesgt
15Lesson 5.Interaction Diagram
16Contents
- Introduction
- Sequence Diagram
- Collaboration Diagram
- Concurrent Processes
17Interaction Diagram
- Interaction Diagram
- describes how groups of objects collaborate in
some behavior. - captures the behavior of a single use-cases.
- shows a number of objects and the messages passed
between these objects within the use-case. - Two kinds
- Sequence Diagram
- Collaboration Diagram
18Collaborations
- The objects interact the other objects to perform
some task together. - Use case Order Stock
- 1) Order Entry Window sends prepare message to
an Order. - 2) Order sends prepare message to each Order
line. - 3) Order line checks the given Stock line
- If true, remove the quantity of Stock Item.
- Otherwise, request a new delivery.
- A collaboration consists of
- Objects
- Links
- Actors
19Sequence Diagram
anOrderEntry Window
anOrder
anOrderLine
aStockItem
prepare()
prepare()
condition
check()
Checktrue remove
message
iteration
needsToReorder()
self-delegation
needToReorder()true
return
new
aReorderItem
Checktrue new
aDeliveryItem
lifeline
creation
20Notation
- Lifeline
- Represents the objects life during the
interaction. - Message Flow
- Each message is represented by an arrow between
the lifelines of two objects. - Each message is labeled with the message name,
and possibly arguments and control information. - Self-Delegation
- A message that an object sends to itself.
21Notation
- Condition(Guard)
- A message is sent only if the condition is true.
- needToOrder() true
- Iteration Marker
- A message is sent many times to multiple receiver
objects. - When a collection is iterated over.
- Return
- Indicates the return from a message.
- However, returns are implied for all messages.
- Hence, it is used to improve clarity.
22Variants of Message Sending
Interaction type Symbol Meaning Synchrono
us or call The normal procedural
situation. The sender loses control until
the receiver finishes handling the
message. Return Not a message, but a return
from an earlier message. Flat The
message doesnt expect a reply. Control
passes from the sender to the receiver, so
the next message will be sent by the receiver
of this message. Asynchronous The message
doesnt expect a reply, but unlike the flat
case, the sender stays active and may send
further messages.
23Case Study Library System
theLibraryMember LibraryMember
theCopy Copy
theBook Book
aMember BookBorrower
borrow(theCopy)
1okToBorrow
2borrow
2.1 borrowed
24System Sequence Diagram
- Events that external actors generate
- Use case Buy-items
- POST checkout with items to purchase
- Cashier records UPC from each item. If same item,
enter the quantity. - System determines the item price and adds item
information to the running sales transaction.
25System Sequence Diagram
System
Cashier
enterItem(UPC, quantity)
Actor
endSale()
System event
makePayment(amount)
System
endSale() enterItem() makePayment()
26Concurrent Processes
aTransaction
Asynchoronous Message
aTransaction Coordinator
new
aFirst Transaction Checker
Activation
new
aSecond Transaction Checker
new
ok
Other processing suppressed
all done?
ok
bevalid
all done?
self delegation
27Concurrent Notation
- Activation
- is used to indicate a transaction
- Asynchronous Message
- Notation Half-arrow heads
- Does not block the caller, so the caller carry on
with its own processing - Deletion
- Object deletion can be marked with a large X.
- It can self-destruct or be destructed by another
message.
28Asynchoronous Message
- do one of three things
- create a new thread
- create new object
- communicate with thread
- Text blocks
- When a Transaction
- is created.
- . it creates a
- Coordinator to
- message the checking.
- The coordinator
- creates a series
- of Checker, one
- for each kind of
- check.
aTransaction
aTransaction Coordinator
new
aFirst Transaction Checker
new
new
ok
all done?
29Collaboration Diagram
- Definition
- Collaboration diagram represents object
interactions in a graph or network format.
1message2() 2 message3()
message1()
ClassAInstance
ClassBInstance
- Numbering messages
- Single number 1, 2, 3, .
- Decimal number 1, 1.1, 1.1.1, 1.1.2, .
30Collaboration Diagram
Object
OrderEnrtyWindow
Message
1 prepare()
Sequence Number
Order
5 needToReorder()
3 check() 4checktrue remove()
2 prepare()
MacallanlineOrderLine
Macllan stock Stock Item
Self delegation
6 new
7checktrue new
Delivery Item
Reorder Item
31Collaboration Diagram
Object
OrderEnrtyWindow
Message
1 prepare()
Sequence Number
Order
1.1.2.1 needToReorder()
1.1.1 check() 1.1.2checktrue remove()
1.1 prepare()
MacallanlineOrderLine
Macllan stock Stock Item
Self delegation
1.1.2.2 new
1.1.3checktrue new
Delivery Item
Reorder Item
32Creation and Deletion of Objects
Lecturer
UTO
1ngetName()
DirectorOfStudies
2 new DirectorOfStudies(n)
3 destroy()
33Creation and Deletion of Objects
Lecturer destroyed
1 ngetName()
3destroy()
UTO
2 new DirectorOfStudies(n)
DirectorOfStudies new
34Timing
theLibraryMember LibraryMember
theCopy Copy
theBook Book
aMember BookBorrow
borrow(theCopy)
1okToBowwor
A
2borrow
C-Alt5 sec
2.1 borrowed
B
B
C
35Conditional Behavior
- A message may be guarded by a condition.
- The message is sent only if the guard is true.
- Condition in square brackets
- Mutually exclusive/Concurrent conditions
mMung
mMung
I0 foo()
I0 foo()
I1 bar()
I1 bar()
36Iteration
- Send message number of times
- A message is marked with asterisk.
- Iteration clause describes how many times the
messages will be sent. - ex) i1..10, x , 10, item not found,
true
tFoo
Bar
Baz
3.1I1..2a()
3.1.1 b()
37Iteration
msg1()
1I1..10 msg2()
A
myB B
2I1..10msg3()
myC C
msg1() for(I1 Ilt10 I)
myB.msg2() myC.msg3()
38Comparison
- Sequence Diagram
- easy to see order
- simple
- Collaboration Diagram
- more complex behavior
- indicate how objects are statically connected
39Lesson 6.The Other Diagrams
40Contents
- Package Diagram
- State Diagram
- Activity Diagram
- Deployment Diagram
41Part 1Package Diagram
42Motivation
- How break a large system into smaller systems?
- Structured Methods
- Functional decomposition
- Like use cases in OO methods
- Information Engineering
- Grouping data records into subject area
- Produces metrics to show how the functions and
records interact. - UML
- Grouping classes together into high-level units,
packages.
43Package Diagram
- Definition
- A diagram that shows packages of classes and the
dependencies among them. - It is just a form of class diagram.
- Dependencies
- Between Classes(on Class Diagram)
- One class send a message to another.
- One class has another as part of its data.
- One class mentions another as a parameter to an
operation. - Between Packages(on Package Diagrams)
- Exist if any dependency exists between any two
classes in the packages. - Notation
- Put the name of the package inside the main box
- Minimize dependency
44Package Diagram
Package
Dependency
45Package Dependency
- Package Dependency is not a compilation
dependency. - Not a transitive relationship
- The sementics of the Java import behavior
46Package Visibility
- Visibility shows subpackage.
- Definition
- a class contains methods that can be seen by
other objects within the same package, but not by
objects that belong to other packages. - Types
- see into nested packages - transparent
- cannot see - opaque
- Java has package visibility.
47Advanced Package Diagram
Domain
48Part 2State Diagram
49State Diagram
- Concept
- A state diagram describes all the possible states
of an object and the transitions between the
states. - Objects state changes as a result of events
- Syntax and Semantics of Transition
- Event Guard / Action
- When the event happens, then transition can
begin. - If the Guard part is specified, the transition
occurs only when the guard condition is evaluated
to true. - Then, the Action is performed and the object
gets into the new state.
50Behavior Inside a State
- entry/action
- The entry action is executed whenever the given
state is entered via a transition. - do/activity
- While staying in the state,
- the activity is performed.
- exit/action
- The exit action is executed whether the state is
left via a transition. - event/action(argument)
- If a state responds to an event with an action
that does not cause a transition.
entry/action do/activity exit/action event/actio
n(arguments)
Dispaching
51State Diagram
/get first item
get next item Not all items checked
All items checked all items available
Item Received All items available
All items checked some items not in stock
Activity
Delivered
Ungarded Transition
Self-transition
transition
Item Received Some items not in stock
state
52Superstates
- Concept
- When several states have common transitions, the
states can be grouped into a superstate. - Then, the substates inherit any transition on the
superstate.
53Without Superstates
get next item Not all items checked
/get first item
All items checked all items available
Item Received All items available
All items checked some items not in stock
Delivered
cancel
Waiting
cancel
Item Received Some items not in stock
cancel
Delivered
Cancelled
54With Superstate
superstate name
get next item Not all items checked
Active
/get first item
All items checked all items available
Item Received All items available
All items checked some items not in stock
Waiting
Delivered
Item Received Some items not in stock
cancel
Delivered
Cancelled
55Concurrent State Diagram
- Concept
- If an object exhibits a combination of behaviors,
then the associated states can be combined on a
concurrent state diagram. - Concurrent state diagrams are useful when a given
object has sets of independent behaviors. - Example
- Order Processing and Payment Authorization can be
combined. - The given Order object is in two different
states.
56Concurrent State Diagrams
- State Diagram for
- Payment Authorization
Authorizing do/check payment
Authorized
Rejected
Delivered
57Concurrent State Diagrams
cancelled
Cancelled
Waiting
Checking
Dispaching
Delivered
Authorizing
Autorized
Rejected
58Concurrent State
- Object exhibits a combination of the behaviors
- Order State
- availability of items
- payment authorization
59Part 3Activity Diagrams
60Concept
- Origins
- Event Diagram of Jim Odell, SDL State Modeling
technique, and Petri-nets. - Activity
- Conceptually, a some task to be carried out
- Specifically, a Method on a class
- Activity Flow
- Flow Order of the Activities
- Guard
- Logical expression evaluated prior to running
activity
61Elements of Activity Diagram
- Activity
- represented with rounded box
- Transition
- arrow with guard, represent activity flow
- Synchronization Bar
- Activities under a synchronization bar occur in
parallel, and their order is irrelevant. - Concurrent activities can be implemented in an
interleaving or simultaneous fashion. - Decision Diamond
- alternative to guards on separate transition
- Start and Stop markers
62Usage of Activity Diagram
- Activity diagram is used to describe
- A method
- Complicated methods
- One Use-case
- Multiple use-cases
63Example Serving Beverage
no cola
no coffee
Find Beverage
Guard
Synchronization Bar
found coffee
Decision Activity
found cola
Put Coffee in filter
Add Water to Reservior
Get Cups
Get Can of Cola
Put Filter in Machine
Activity
Turn On Machine
coffeePot.TurnOn
End
Brew Coffee
light goes out
Pour Coffee
Drink Beverage
64Example Receive Order
- Multiple Trigger
- Indicate the basis
- of the trigger
Receive Order
Multiple Trigger
For each line item on order
Cancel Order
Authorize Payment
Check Line Item
failed
in stock
succeeded
Assign to Order
Synchronization Condition
stock assigned to all line items and payment
authorized
need to reorder
Reorder Item
Dispatch Order
65Example Receive Supply
Receive Order
Choose Outstanding Order Items
For each chosen order item
Assign Goods to Order
stock assigned to all line items and payment
authorized
all outstanding order items filled
Dispatch Order
Reorder Item
66Example Combining two Diagrams
Receive Order
Receive Order
For each line item on order
Authorize Payment
Check Line Item
Choose Outstanding Order Items
Cancel Order
failed
in stock
Assign to Order
succeeded
For each chosen order item
Assign Goods to Order
need to reorder
Reorder Item
stock assigned to all line items and payment
authorized
all outstanding order items filled
Dispatch Order
Reorder Item
67Swimlanes
Order Processing
Finance
Receive Order
Receive Order
For each line item on order
Stock Manager
Authorize Payment
Check Line Item
Choose Outstanding Order Items
in stock
Reorder Item
Assign to Order
For each chosen order item
Assign Goods to Order
need to reorder
Reorder Item
stock assigned to all line items and payment
authorized
all outstanding order items filled
Reorder Item
Dispatch Order
68Part 4Deployment Diagrams
69Concept
- Definition
- Deployment diagrams shows the physical
relationships among software and hardware
components in the target systems. - Node represents some kind of computation unit.
- Often a piece of hardware
- Connections among nodes show the communication
paths. - Components represent physical modules of code.
- Dependencies are same as package dependencies.
70Example
Diabetes Unit Server
Object Database
Connection
Health Care Domain
Liver Unit Server
Object Domain
ltltcommunicationgtgt
Health Care Domain
Liver Unit configuration
Configure Medical Knowledge
Liver Unit Server Application
Node
Configure Unit
Configuration
Application
A Windows PC
Contained Object
Interface
Liver Unit Client Function
Component
Liver Unit Client Function