Chapter 4 Dynamic Modeling and Analysis Part I

  • Slides: 44
Download presentation
Chapter 4 Dynamic Modeling and Analysis (Part I) Object-Oriented Technology From Diagram to Code

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 Mc. Graw-Hill Education (Asia), 2005 1

References n n Chapter 4, Object-Oriented Technology: From diagram to code with Visual Paradigm

References n n Chapter 4, Object-Oriented Technology: From diagram to code with Visual Paradigm for UML Chapters 15, 18, 21, The UML User Guide 2

What You Will Learn n n Model message flows using sequence diagrams. Model message

What You Will Learn n n 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. 3

Scenario Modeling Techniques – Interaction Diagram n n n Scenario modeling describes how the

Scenario Modeling Techniques – Interaction Diagram n n n 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. 4

Scenario Modeling Techniques – Interaction Diagram (cont’d) n n n An interaction diagram can

Scenario Modeling Techniques – Interaction Diagram (cont’d) n n n 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. 5

Common UML Interaction Diagram Notation n Object Symbol Naming Format Notation An object of

Common UML Interaction Diagram Notation n 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. 6

Object Stereotype Object Category Description Actor Object An external entity that interacts with the

Object Stereotype Object Category Description 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. Graphical Notations 7

Object Stereotype (cont’d) Object Category Description Boundary Object An object that handles the communication

Object Stereotype (cont’d) Object Category Description 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. Graphical Notations 8

Messages Message Description Procedure call or other nested flow of control The message sender

Messages Message Description 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. Notation 9

Messages (cont’d) Message Description Return message Message returned from the procedure call. Message with

Messages (cont’d) Message Description 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. ) Notation 10

Sequence Diagrams n n An interaction diagram models the behavior of a group of

Sequence Diagrams n n 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. 11

Sequence Diagrams (cont’d) 12

Sequence Diagrams (cont’d) 12

Life Line & Activation Object with Lifeline Object with Activation 13

Life Line & Activation Object with Lifeline Object with Activation 13

Creation & Destruction Object Creation Object Destruction 14

Creation & Destruction Object Creation Object Destruction 14

Branching Conditional Message Transmission 15

Branching Conditional Message Transmission 15

Message that Takes Time Message Transmission that Takes Time 16

Message that Takes Time Message Transmission that Takes Time 16

Iteration 17

Iteration 17

Alternate Message Reception 18

Alternate Message Reception 18

Recursion 19

Recursion 19

Example Creation Life line Deletion 20

Example Creation Life line Deletion 20

Example Life line iteration Activation 21

Example Life line iteration Activation 21

Example Life line collective iteration 22

Example Life line collective iteration 22

Example Concurrent Branch 23

Example Concurrent Branch 23

Collaboration Diagrams n n n Collaboration diagrams provide another way to model a scenario.

Collaboration Diagrams n n n 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. 24

Collaboration Diagrams (cont’d) 25

Collaboration Diagrams (cont’d) 25

Example – Telephone System 26

Example – Telephone System 26

Example – Message with Duration 27

Example – Message with Duration 27

Example – An Automatic Teller Machine (ATM) n n n The ATM prompts the

Example – An Automatic Teller Machine (ATM) n n n 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. 28

Example 1 – An Automatic Teller Machine (cont’d) n n n The user enters

Example 1 – An Automatic Teller Machine (cont’d) n n n 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. 29

Example – An Automatic Teller Machine (cont’d) 30

Example – An Automatic Teller Machine (cont’d) 30

Example – An Automatic Teller Machine (cont’d) 31

Example – An Automatic Teller Machine (cont’d) 31

Example – An Automatic Teller Machine (cont’d) 32

Example – An Automatic Teller Machine (cont’d) 32

Example - A Soft Drink Vending Machine 33

Example - A Soft Drink Vending Machine 33

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

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

Dynamic Modeling Techniques Using Statechart Diagrams n n The behavior of an entity is

Dynamic Modeling Techniques Using Statechart Diagrams n n 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 an entity responds to various events by changing from one state to another. 35

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

What Is a State? n n 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: n n balance : = balance – withdraw. Amount; 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. 36

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

What Is a State? (cont’d) n There are several characteristics of states: n n n 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. 37

UML Notation 38

UML Notation 38

UML Notation (cont’d) Action or activity Description entry/ action 1; …; action n Upon

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) An internal transition is fired when the [guard-condition] / action specified event occurs and the specified 1 ; …; action n guard condition is true. The specified actions are performed when the transition is fired. 39

UML Notation (cont’d) Initial state Final state State History state Junction state Concurrent composite

UML Notation (cont’d) Initial state Final state State History state Junction state Concurrent composite state Transition 40

Transition n A transition from one state to another takes place instantaneously in response

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

Transition (cont’d) n A transition is fired when the following conditions are satisfied: n

Transition (cont’d) n A transition is fired when the following conditions are satisfied: n n 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. 42

Composite State 43

Composite State 43

Composite State (cont’d) 44

Composite State (cont’d) 44