1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code...

44
1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence S.W. Lau and Y.K. Leung McGraw-Hill Education (Asia), 2005

Transcript of 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code...

Page 1: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

1

Chapter 4Dynamic Modeling and

Analysis (Part I)

Object-Oriented TechnologyFrom Diagram to Code with Visual Paradigm for

UML

Curtis H.K. Tsang, Clarence S.W. Lau and Y.K. Leung

McGraw-Hill Education (Asia), 2005

Page 2: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

2

References Chapter 4, Object-Oriented

Technology: From diagram to code with Visual Paradigm for UML

Chapters 15, 18, 21, The UML User Guide

Page 3: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

3

What You Will Learn Model message flows using sequence

diagrams. Model message flows using the

collaboration diagrams. Model lifetime behaviors of an object

using statechart diagrams. Model performance of actions of a

procedure or an activity using activity diagrams.

Page 4: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

4

Scenario Modeling Techniques – Interaction Diagram

Scenario modeling describes how the objects in a system interact with each other in a scenario.

A scenario is a sequence of events that occurs during one particular execution path within a use case of a system.

Each event involves the interaction of objects passing messages between them.

Page 5: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

5

Scenario Modeling Techniques – Interaction Diagram (cont’d) An interaction diagram can be used to model the

collaborating objects in scenarios, showing the objects involved in the scenario and the messages sent and received by them.

These objects may be external or internal to the system.

The messages represent the invocation of operations of the receiving objects.

Two kinds of interaction diagrams: sequence diagrams and collaboration diagrams.

Sequence diagrams focus on the time sequencing of messages.

Collaboration diagrams focus on the structural organization of the links between collaborating objects.

Page 6: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

6

Common UML Interaction Diagram Notation Object Symbol

Naming Format Notation

An object of an unspecified class.

A named object of a specified class.

An unnamed object of a specified class.

Page 7: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

7

Object Stereotype

Object Category

Description Graphical Notations

Actor Object An external entity that interacts with the system.

Entity Object 

An object that models the data in the system. It often represents an object in the problem domain.

Page 8: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

8

Object Stereotype (cont’d)

Object Category

Description Graphical Notations

Boundary Object

An object that handles the communication between actor objects and the system.

Control Object  

An object that models the flow of control and functionality that do not naturally belong to entity objects or boundary objects.

Page 9: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

9

Messages

Message Description Notation

Procedure call or other nested flow of control

The message sender waits for the completion of the procedure call of the message receiver.

Asynchronous communication

The sender dispatches a message and immediately continues with the next step of execution.

Page 10: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

10

Messages (cont’d)

Message Description Notation

Return message

Message returned from the procedure call.

Message with travel delay

The message will take a significant amount of time to arrive at the receiving object. (This is only used in sequence diagrams.)

Page 11: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

11

Sequence Diagrams An interaction diagram models the behavior of a group

of objects that work together to achieve a user goal. A sequence diagram helps us identify a set of

collaborating objects involved in a scenario of a use case.

A sequence diagram has two dimensions: the vertical dimension and the horizontal dimension, respectively representing the passage of time and the objects involved in the interaction.

Object icons are placed horizontally at the top of the sequence diagram, and messages are passed between them.

Page 12: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

12

Sequence Diagrams (cont’d)

Page 13: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

13

Life Line & Activation

Object withLifeline

Object withActivation

Page 14: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

14

Creation & Destruction

ObjectCreation

ObjectDestruction

Page 15: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

15

Branching

ConditionalMessageTransmission

Page 16: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

16

Message that Takes Time Message Transmission that Takes Time

Page 17: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

17

Iteration

Iteration

Page 18: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

18

Alternate Message Reception

AlternateMessageReception

Page 19: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

19

Recursion

Recursion

Page 20: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

20

Example

Life line

Creation

Deletion

Page 21: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

21

Example

Life line

Activation

iteration

Page 22: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

22

Example

Life linecollective iteration

Page 23: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

23

Example

Concurrent Branch

Page 24: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

24

Collaboration Diagrams Collaboration diagrams provide another way to model a

scenario. Shows the roles of objects and associations of objects in

an instance of collaboration. Focus on structures of the objects rather than temporal

sequence of operations. In a collaboration diagram, each object is represented

by an object icon, and links are used to indicate communication paths on which messages are transmitted.

Collaboration diagram = object diagram + messages between objects.

Messages are presented in the same way as those in a sequence diagram; in fact, sequence diagrams and collaboration diagrams are semantically equivalent.

Page 25: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

25

Collaboration Diagrams (cont’d)

Page 26: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

26

Example – Telephone System

Page 27: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

27

Example – Message with Duration

Page 28: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

28

Example – An Automatic Teller Machine (ATM) The ATM prompts the user to insert a card. The user inserts an ATM card. The ATM prompts the user to input the PIN. The user enters the PIN. The ATM asks the bank consortium to verify the ATM card

number and PIN. The bank consortium verifies the ATM card number and PIN

with bank. The bank notifies the bank consortium that the PIN is correct. The bank consortium notifies the ATM the PIN is correct. The ATM prompts the user to select a service. The user selects the withdraw cash service. The ATM prompts the user to enter the amount to withdraw.

Page 29: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

29

Example 1 – An Automatic Teller Machine (cont’d) The user enters the amount to withdraw. The ATM asks the bank consortium to process the request. The

bank consortium forwards the request to bank. The bank confirms the successful execution of the request to

the bank consortium which in turn notifies the ATM that the request has been approved.

The ATM displays the successful transaction screen, ejects card and then dispenses cash requested.

The ATM shows the main menu to the user for selecting the next service.

Page 30: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

30

Example – An Automatic Teller Machine (cont’d)

Page 31: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

31

Example – An Automatic Teller Machine (cont’d)

Page 32: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

32

Example – An Automatic Teller Machine (cont’d)

Page 33: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

33

Example - A Soft Drink Vending Machine

Page 34: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

34

Example - A Soft Drink Vending Machine (cont’d)

Page 35: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

35

Dynamic Modeling Techniques Using Statechart Diagrams The behavior of an entity is not only a direct

consequence of its inputs, but it also depends on its preceding state.

The past history of an entity can best be modeled by a finite statechart diagram traditionally named “automata”.

Statechart diagrams (or sometimes referred to as state diagrams) show the different states of an entity.

Statechart diagrams can also show how an entity responds to various events by changing from one state to another.  

Page 36: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

36

What Is a State? According to Rumbaugh et al. “A state is an

abstraction of the attribute values and links of an object. Sets of values are grouped together into a state according to properties that affect the gross behavior of the object.”

For example, consider you have $100,000 in a bank account. The behavior of the withdraw function would be:

balance := balance – withdrawAmount; provided that the balance after the withdrawal is not less than $0;

However, if the account balance becomes negative after a withdrawal, the behavior of the withdraw function would be quite different.

Page 37: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

37

What Is a State?(cont’d) There are several characteristics of states:

A state occupies an interval of time. A state is often associated with an abstraction of

attribute values of an entity satisfying some condition(s).

An entity changes its state not only as a direct consequence of the current input, but it is also dependent on some past history of its inputs.

Page 38: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

38

UML Notation

Page 39: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

39

UML Notation (cont’d)Action or activity Description

entry/ action 1; …; action n

Upon entry to the state, the specified actions are performed.

exit/ action 1; …; action n Upon exit from the state, the specified actions are performed.

do/ activity The specified activity is performed continuously while in this state.

event-name(parameters) [guard-condition] / action 1 ; …; action n

An internal transition is fired when the specified event occurs and the specified guard condition is true. The specified actions are performed when the transition is fired.

Page 40: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

40

UML Notation (cont’d)

Initial state

Final state

State

History state

Junction state

Concurrent composite state

Transition

Page 41: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

41

Transition

A transition from one state to another takes place instantaneously in response to some external events or internal stimuli.

Page 42: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

42

Transition (cont’d)

A transition is fired when the following conditions are satisfied: The entity is in the state of the source

state. An event specified in the label occurs. The guard condition specified in the label

is evaluated to be true. When a transition is fired, the actions

associated with it are executed.

Page 43: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

43

Composite State

Page 44: 1 Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence.

44

Composite State (cont’d)