Hiểu biết về mô hình hóa động - Pdf 21

Understanding
Dynamic Modeling
Chapter 7
An object-oriented design should represent the structural
and behavioral aspects of a software system. Static
modeling is used to represent the structural constituents of
a software system. Dynamic modeling is used to represent
the behavior of the structural constituents. Dynamic
modeling uses various types of diagrams, such as
interaction, state, and activity diagrams.
This chapter explains the concept of dynamic modeling.
In addition, it explains how to create the dynamic model
of a system by using interaction diagrams.
In this chapter, you will learn to:
 Identify the concepts of dynamic modeling
 Create interaction diagrams
Objectives

¤NIIT Understanding Dynamic Modeling 7.3
Dynamic modeling is a UML modeling technique that represents the behavior of the static
constituents of a software system. Therefore, it is also known as behavioral modeling. A
designer requires dynamic modeling techniques to represent the interaction, workflow,
and different states of the static constituents in a software system.
The design of a software system is considered to be the good if it is able to represent what
a system should do and how. Without a good design a developer will not be able to code a
program correctly. This is because coding involves the implementation of the design.
Modeling techniques are required to represent all aspects of a software system. These
modeling techniques help in representing the system requirements, the static constituents
of a system, its behavior, and architecture.
Dynamic modeling techniques help the designer to represent the behavior of the static
constituents so that a developer is able to depict how a system should behave to meet the

constituents of a software system.
Therefore, it is also known as behavior
modeling.
It includes class and object diagrams.
It includes interaction, activity, and state
diagrams.
It helps in depicting the relationships
and dependencies between the
constituents of a system.
It helps in expressing and modeling the
behavior of a system over a period of time.
Difference between Static and Dynamic Modeling
Difference between Static and Dynamic Modeling
¤NIIT Understanding Dynamic Modeling 7.5
N
ote
Interaction diagrams depict how the constituents of a software system interact to realize
the use cases of the system. In addition, you can use interaction diagrams to generate
executable code through forward and reverse engineering. The two components of an
interaction diagram are:
 Collaboration: Depicts the static aspect of an interaction diagram.
 Interaction: Depicts the dynamic aspect of an interaction diagram.
A collaboration is a collection of instances of classes, the relationship among the
instances of classes, and actors. A collaboration groups all the components that are
required to realize a use case. The relationships among the components of a collaboration
are graphically depicted as links between objects. A link serves as a path over which
messages are sent and received.
Although, abstract classes and interfaces do not have instances, they can form a part of
a collaboration.
You use interactions to depict the flow of control in an operation or among use cases. In

 Association roles: Describes the links that can form a part of the collaboration.
An interaction signifies the collection of communications that occur among the
classifier roles across the association roles. A collection of communications indicates
the messages that flow from one classifier role to another.
¤NIIT Understanding Dynamic Modeling 7.7
When an object calls the methods of another object, a sequence of messages flow between
them. The following table lists the various types of messages that can be sent from one
object to another and their graphical representation in an interaction diagram.
Message Description Graphical Representation
Call
Specifies the invocation of a method of
an object.
Return Returns a value to the calling method.
Send
Sends an asynchronous signal to an
object.
Create Creates an object.
Destroy Destroys an object.
The commonly used interaction diagrams are Sequence diagram and Communication
diagram. Let us, discuss how to create these diagrams.
Sequence diagrams represent an interaction among objects in the form of messages
ordered in a sequence by time. In a sequence diagram, you arrange objects across the
x-axis. You place the object that starts an interaction to the extreme left. The objects that
come later in the message sequence are placed to the right of the interaction-initiating
object. The messages sent and received by the objects in an interaction are placed along
the y-axis in an increasing order of time.
Creating Sequence Diagrams
7.8 Understanding Dynamic Modeling ¤NIIT
The following figure depicts the arrangement of objects and messages in a sequence
diagram.

details in the
Inventory Database. When the details are stored in the database, the
order object receives a Transaction Complete signal and is then destroyed.
When an object invokes its own method or receives a callback from another object, a new
focus of control is represented over the existing focus of control and is called a nested
focus of control.
7.10 Understanding Dynamic Modeling ¤NIIT
N
ote
The following figure shows the nested focus of control of an object.
Nested Focus of Control
Unlike sequence diagrams, communication diagrams do not depict the object lifeline.
In a sequence diagram, the flow of control depicts a sequential flow of messages.
However, a programming logic may require you to depict the iterations of messages or the
branching of the flow of control. Iterations are repetitions of messages. You can use the
following statement to depict an iteration in a sequence diagram:
*[ j := 1 n ]
You use an asterisk, *, to indicate that the message is being sent repeatedly. You can
depict iteration by using the following notations:
 [j < 10]: Specifies that the message will be sent until the value of j is less than 10.
 [val not found]: Specifies that the message will be sent until val is found.
¤NIIT Understanding Dynamic Modeling 7.11
The following sequence diagram depicts that the Math object requests the
numberProperties object to calculate if a number is prime or not, iteratively.
Iteration in Sequence Diagrams
Branching of messages occurs when a set of messages responds to a call. The message to
be sent is guarded by a condition, which is a Boolean expression. If the condition
evaluates to true, then the first message is sent, otherwise, the second message is sent.
There is no specification on what type of conditions you may include in your interaction
diagrams. You can use either an English language expression or a programming language

parts
Inventory
Database
o1:
order
[qty>CriticalLevel]
Transaction Complete
Store Order Details
Inventory Manager
¤NIIT Understanding Dynamic Modeling 7.13
N
ote
The guidelines that you need to follow when you model a sequence diagram are:
 Identify the collaboration for an interaction in the system, subsystem, and use cases.
 Identify the objects that have higher responsibility in the interaction. To draw a
sequence diagram, place the objects with high responsibility on one side and the low
responsibility objects on the other.
 Identify the lifeline of each object in view of the control to depict the creation and
destruction of an object.
 Identify the messages that flow between the lifeline of objects. You also need to
identify the properties of these messages to obtain information about the semantics of
the interaction.
 Identify the preconditions and post conditions for each message to control the flow
of objects.
Communication diagrams represent the interaction among objects in the form of
messages. To draw a communication diagram, you identify the objects in collaboration
and represent them as the vertices of a graph. After you place the objects, you can draw
straight lines that represent the links among these objects to connect the objects. Note that
objects send and receive messages across these links. The dynamic aspect of an
interaction diagram can be depicted by messages that are passed among objects across

Communication Diagram with Sequenced Messages
Sequence and collaboration diagrams are isomorphic. This means that they contain the
same information and can be derived from each other. While sequence diagram depicts
the time sequencing of messages, the communication diagram depicts structural
responsibilities of the participating objects.
Sequence and communication diagrams are similar because of the fact that both represent
collaboration and the messages flowing between the constituents of the collaboration.
You can also depict iterations and conditions in a communication diagram in the same
way as in sequence diagrams. You can derive a communication diagram from a sequence
diagram by using the objects and messages of the sequence diagram. Organize the objects
so that the related objects are placed together and place a sequence number before each
¤NIIT Understanding Dynamic Modeling 7.15
message in the communication diagram based on the time ordering depicted in the
sequence diagram.
Similarly, you can derive a sequence diagram from a communication diagram by using
the objects and messages of the communication diagram. Place the objects and draw their
respective object lifelines. Draw the messages among objects according to the sequence
specified in the communication diagrams.
The guidelines that you need to follow when you model a communication diagram are:
 Identify the collaboration that involves an interaction in the system, subsystem, and
use cases.
 Identify the objects that have higher responsibility in the interaction. Draw these
objects on a graph so that the objects with high responsibility are placed on one side
and the objects with lower responsibility are placed on the other.
 Identify the links among objects. You need to place the association links to depict the
relationship among objects.
 Identify all the messages that flow across the links established among objects.
Assigning Responsibilities to Classes
You need to assign responsibilities to a class or a set of classes to ensure that the software
system has the required functions to suit the requirement document.

 Check if too many or unrelated responsibilities have been assigned to a class. If such
a class exists, split the class into smaller classes.
¤NIIT Understanding Dynamic Modeling 7.17
Just a minute:
Which of the following diagrams represents the interaction among objects in the form
of messages?
1. Composite structure diagram
2. Communication diagram
3. Timing diagram
4. Interaction Overview diagram
Answer:
2. Communication diagram
7.18 Understanding Dynamic Modeling ¤NIIT
Problem Statement
Janes Technology has been assigned the task of creating a dynamic model of the
prototype for the InfoSuper bank ATM system. Janes Technology needs to implement
only the cash withdrawal system in the prototype for the InfoSuper bank. The following
table describes the classes, attributes, and operations for the cash withdrawal feature of
the InfoSuper bank, which the design team of Janes Technology has identified.
Class Operations Description
ATM Show()
Displays the location and
branch name of the ATM.
GetPin()
Accepts the PIN entered by the
customer and verifies it.
GetAccount()
Fetches the account
information based on the
card_ID and PIN.

ATM System
¤NIIT Understanding Dynamic Modeling 7.19
Class Operations Description
VerifyWithdrawalAmount()
Verifies if the amount to be
withdrawn is less than the
account balance amount.
CurrentAccount CalculateInterest()
Calculates the interest for the
current account.
SavingsAccount CalculateInterest()
Calculates the interest for the
savings account.
GetAccountBalance()
Gets the balance of the
account.
StartTransaction() Initiates the transaction.
Transaction
CancelTransaction Cancels the transaction.
AcceptCard() Accept/rejects the ATM card.
ReadCard()
Reads the Card_ID associated
with the ATM card.
EjectCard() Ejects the ATM card.
CardScanner
ValidatePIN() Validates the pin number.
Prompt()
Prompts the respective screen
according to the request.
DisplayScreen

BankCustomer Supply the PIN number.
Select the type of transaction.
Supply the amount to be withdrawn.
CardScanner Accept and read the card information.
Eject the card after the transaction is complete.
DisplayScreen Prompt the user for input.
ATMCard Verify the PIN number.
Get the information about the customer’s account.
Account Verify the PIN number.
Get the information about the customer’s account.
Verify the amount to be withdrawn.
Update the amount in the account after the transaction.
Transaction Starts a transaction.
Get the cash balance from the account.
CashDispenser Supply cash to the customer.
Generate a receipt of the transaction.
Class Responsibilities
7.22 Understanding Dynamic Modeling ¤NIIT
The following figure depicts the sequence diagram for the cash withdrawal feature of the
InfoSuper bank ATM system.
Sequence Diagram for the InfoSuper Bank ATM System
¤NIIT Understanding Dynamic Modeling 7.23
The following figure depicts the communication diagram for the cash withdrawal feature
of the InfoSuper bank ATM system.
Communication Diagram for the InfoSuper Bank ATM System
Task 2: Creating a Sequence Diagram
To create a sequence diagram, you need to perform the following steps:
1. Select StartÆAll ProgramsÆMicrosoft OfficeÆMicrosoft Office Visio for
Enterprise Architects.
2. Open the Bank_ATM Visio file. The Bank ATM model appears.


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status