Chapter 2-Part III Behavioral Models: Sequence diagram and Activity Diagram Object-Oriented System...
-
Upload
claud-hancock -
Category
Documents
-
view
216 -
download
1
Transcript of Chapter 2-Part III Behavioral Models: Sequence diagram and Activity Diagram Object-Oriented System...
Chapter 2-Part III Behavioral Models:
Sequence diagram and Activity Diagram
Object-Oriented System Anaysis and Design
3
Overview
In every system, objects do not just sit idle; they interact with one another by passing messages.
In the UML, the dynamic aspects of a system is modelled using interactionsAn interaction sets the stage for its behaviour by
introducing all the objects that work together to carry out some
action, and the messages that are dispatched from object to object
4
DefinitionAn interaction is a behaviour that comprises
a set of messages exchanged among a set of objects within a context to accomplish a purpose
Interactions can be found wherever objects are linked to one another, e.g.in the collaboration of objects that exist in the
context of a system and subsystem as a wholeamong objects in the implementation of an
operationin the context of a class in order to visualize,
specify, construct and document the semantic of a class
5
Messages & ActionsA message is a communication
between two objects, or within an object, that is designed to result in some activity.
This activity involves one or more actions, which are executable statements that result in changes in the values of one or more
attributes of an object, or the return of some value(s) to the object
that sent the message, or both
6
There are 5 kinds of actions that the UML explicitly supports: -Call and ReturnCreate and DestroySend
7
Call actionA call action invokes an operation on an objectIt is synchronous, meaning that
the sender assumes that the receiver is ready to accept the message,
and the sender waits for a response from the receiver before proceeding
The UML represents a call action as an arrow from the calling object to the receiving object
: Class Object: Class
action name
action name
A call action that involves two objects
A call action from an object to itself
A lifeline
8
Return actionA return action is the return of a value to the
caller, in response to a call actionThe UML represents a return action as a
dashed arrow from the object returning the value to the object receiving the value
: Class Object: Class
return value
9
: Customer : CustomerReview
assignRating()
computeAvgRating()
average rating
Example :- Call and Return action
10
Create actionA create action creates an object
It tells a class to create an instance of itselfIn the UML, create action is represented as an
arrow with the stereotype <<create>> from the object that invokes the create action to the created object
Object: Class : Class
<<create>>
Object: Class
: Class<<create>>
Alternate Create Action notation
11
Destroy actionA destroy action destroys an object
It tells an object to destroy itselfAn object can perform a destroy action on another
object, or on itselfIn the UML, a destroy action is represented as an arrow
with the stereotype <<destroy>> from the object that invokes the action to the destroyed object. A large X is also added at the end of the destroy arrow to denote that the object’s lifeline has been terminated
Object: Class : Class
<<destroy>>X
12
Send actionA send action sends a signal to an objectA signal is an asynchronous communication
between objectsOne object “throws” a signal to another object that
“catches” the signalThe sender of the signal does not expect a response from
the receiver (unlike the sender of a call action)Exceptions are the most common type of signals
In the UML, a send action is represented as an arrow with a half arrowhead at the lifeline of the receiving object
: Class Object: Class
action name
13
Modelling an interactionWhen modelling an interaction, we need to include both objects and messageseach object plays a specific roleeach message represents the communication between objects, with some resulting action
Cont…We can visualize objects and messages in an interaction in two ways: -by emphasizing the time ordering of its message : sequence diagram
by emphasizing the structural organization of the objects that send and receive messages : collaboration diagram
Both sequence and collaboration diagram are examples of interaction diagrams
15
Cont… In the UML, an interaction diagram is used to model the dynamic aspect of a system.
These dynamic aspect may involve : -the interaction of any kind of instance in any view of a system’s architecture, including instances of a class, interface, components and nodes.
a system as a whole, a subsystem, an operation or a class
16
An interaction diagram can be used in two ways: -To model flows of control by time orderingemphasizes the passing of messages as they
unfold over timeSequence Diagram is used to model this
To model flows of control by organizationemphasizes the structural relationships
among the instances in the interaction, along which messages may be passed
Collaboration Diagram is used to model this
17
Sequence diagram A sequence diagram is an interaction
diagram that emphasizes the time ordering of messages
A sequence diagram is formed by: - Placing the objects that participate in the
interaction at the top of the diagram, along the X-axis The object that initiates the interaction is
placed on the left most, and the other subordinate objects are placed to the right
Cont..Placing the messages that these objects send and receive along the Y-axis, in order of increasing time from top to bottom
19
A sequence diagram has four key elements: -Objects appear along the top margin
Each object has a lifeline, which is a dashed line that represent the life and perhaps death of the objectMost objects will be in existence for the duration of the interaction
Objects may also be created during the interaction, or destroyed
Cont…A focus of control, which is a tall
thin rectangle that sits on top of an object’s lifeline It shows the period of time during which
an object is performing an action, either directly or through subordinate procedure
The bottom part of a focus of control can be marked by a return message
Messages show the actions that objects perform on each other and on themselves
21
C : Client
: Transaction<<create>>
p : ODBCProxy
X
setActions(a, d, o)setValues(d, 3, 4)
setValues(a, “CO”)
committed
<<destroy>>
objects
time
focus of control
lifeline
Example of a sequence diagram
22
You built sequence diagrams or collaboration diagrams from the use-case and class diagrams that were built before.Each use cases in a use-case diagram has its corresponding sequence or collaboration diagram
You model the diagrams from the main flow of events, or the alternate flow of events, or the scenarios, of each use case
Every object that you have identified in the sequence or collaboration diagram, MUST have its corresponding class in the class diagram
23
Example: - Modelling a sequence diagram for the log-in use case from the on-line Bookstore Case Study.The main-flow of events that are involved is: -
1. The CUSTOMER clicks the Log-in button on the Home Page.
2. The system displays the Log-in Page.
3. The CUSTOMER enters his/her user ID and password. The
CUSTOMER clicks the OK button.
4. The system validates the log-in information against the ACCOUNT
table in the database.
5. CUSTOMER is an authorised user; the system displays the Personal
Home Page to the CUSTOMER
24
Actors: CustomerMessages and Objects
1. The CUSTOMER clicks the Log-in button on the Home Page.
2. The system displays the Log-in Page.3. The CUSTOMER enters his/her user ID and
password. The CUSTOMER clicks the OK button.
5. The system validates the log-in information against the
ACCOUNT table in the database.6. CUSTOMER is an authorised user; the
system displays the Personal Home Page to the CUSTOMER
25
:HomePage :LoginPage :Account:Customer
clickLogin( )
display( )
enter userID and password
clickOK( )validateLogin(userID, password)
login OK
display( )
The Customer clicks the Login button on the Home Page
The system displays the Login Page
The Customer enters his or her user ID and password, and then clicks the OK button.
The system validates the login information against the persistent Account data …
… and then returns the Customer to the Home Page.
Sequence Diagram
26
Robustness AnalysisSometimes when drawing an interaction
diagram, we may be confused about the objects that are involved.
Because each object that we use in an interaction diagram MUST have its corresponding classes in the class diagram, we may find ourselves in a situation where we have already determined the objects that are needed in an interaction diagram but the objects do not have their corresponding classes in our class diagram.
27
Robustness analysis involves analysing the text of a use case and identifying a first-guess set of objects that will participate in the use case, and then classifying these objects based on their characteristics.It involves defining analysis classes
There are 3 types of analysis classes:boundary classesentity classescontrol classesInstances of each of these analysis classes are
called objects.
28
Boundary objectsis an object with which an actor associated with a use case interacts.if the actor is human, the boundary
object may be a window, screen, dialog box, or menu
if the actor is non-human, the boundary object may be application program interfaces (APIs)
boundary object
29
Entity objectsis an object that contains long-lived information, such as that associated with databases.will be mapped to a table (part of the
database) in the design phaseIt can also contain transient objects, i.e. contents of lists in windows, or search results.
entity object
30
Control objectsis an object that embodies application logiccorrespond with system actions (not actions taken by
actors)are often used to handle things such as coordination and
sequencingare also useful for calculations involving multiple entity objects
will be mapped to codes during implementation phaseused as a connecting tissue between boundary objects
and entity objects.
control object
31
Using the previous example (the log-in use case of the Online Bookstore), we can identify that the HomePage and Log-in Page objects are boundary objects,
whereas the Account object is an entity object.
Therefore, taking this into account, we can draw a new interaction diagram.
32
:HomePage :LoginPage :Account:Customer
clickLogin( )
display( )
enter userID and password
clickOK( )validateLogin(userID, password)
login OK
display( )
The Customer clicks the Login button on the Home Page
The system displays the Login Page
The Customer enters his or her user ID and password, and then clicks the OK button.
The system validates the login information against the persistent Account data …
… and then returns the Customer to the Home Page.
Sequence Diagram
33
SummaryNo single interaction diagram can
capture everything about a system’s dynamic aspectmay need to use many interaction diagrams to model the dynamic aspects of a system as a whole, as well as its subsystem, operations, classes, use cases and collaborations.
34
To model a sequence diagram: -Set the context for the interaction
Whether it is a system, subsystem, operation, class or a scenario of a use case or collaboration
Identify which objects play a role in the interactionPlace them from left-to-right, at the top of the diagram
Set the lifeline for each objectStarting with the message that initiates the
interaction, layout each subsequent message from top to bottom between each lifelinesMay adorn each object’s lifeline with its focus of controlMay also adorn each message with a timing mark and
attach suitable time or space constraintsMay also attach pre or post-conditions to each message
35
On-line Bookstore is a web application that can be accessed by the store’s registered customer, whereby each customer can order books, review one or more books sold in the book store, and sell used books to other customers. Before performing any one of these transactions, the customer must first log-in into the system using their user id and password kept in their account.
Problem: Draw the sequence diagram for the above system
36
From previous discussions, we know that the functional requirements for the Online Bookstore can be seen from the use case diagram (as shown in the next slide)Each of the use cases in the use case diagram
must have its corresponding interaction diagram
We will use the scenarios in the ‘Main flow of events’ for each use case to model the interaction diagram
37
RegisterRegister
Order booksOrder books
Sell used Sell used booksbooks
Review booksReview books
CustomerCustomer
On-line Bookstore SystemOn-line Bookstore System
Log-inLog-in
<<include>><<include>>
<<include>><<include>>
<<include>><<include>>
Check outCheck out<<extend>><<extend>>
(CustID)(CustID)
Use Case Use Case Functional Functional
Requirements Requirements DiagramDiagram
38
:HomePage :LoginPage :Account:Customer
clickLogin( )
display( )
enter userID and password
clickOK( )validateLogin(userID, password)
login OK
display( )
The Customer clicks the Login button on the Home Page
The system displays the Login Page
The Customer enters his or her user ID and password, and then clicks the OK button.
The system validates the login information against the persistent Account data …
… and then returns the Customer to the Home Page.
Log-inLog-in
39
Use Case: RegisterMain flow of events:1. The CUSTOMER clicks the REGISTER button on the Home Page.2. The system displays the Register Page.3. The CUSTOMER enters all of the required information.4. The CUSTOMER clicks the SEND button.5. The system checks that all of the required information were entered. If
yes, the system update the CUSTOMER’s record in the CUSTOMER
and ACCOUNT tables in the database. System displays OK message.Objects:-
CUSTOMER: actorCUSTOMER and ACCOUNT: entity objectsHome Page and Register Page: boundary objects
40
:HomePage :RegisterPage
:Account
:Customer
clickRegister( )
display( )
enter information
clickSEND( ) verify info
display( )
The customer clicks the REGISTER button on the Home Page
The system displays the Register Page
The Customer enters the required information and then clicks the SEND button.
The system checks that all of the required information were entered. If yes, the system updates the CUSTOMER’s record in the CUSTOMER and ACCOUNT tables in the database. The system displays OK message
RegisterRegister
:Customer
<<create>>
<<create>>
41
Case Study: Order BooksMain Flow of events: -
1. The CUSTOMER enters the keyword for a book and clicks the
SEARCH button on the personal Home Page.2. The system displays the matching books on the web
Page.3. The CUSTOMER chooses the desired book and clicks the
ADD TO SHOPPING CART button on the web page. 4. The system adds the book into the CUSTOMER’s Order
table in the database.
Objects:Customer: actorHome Page: boundary objectBook and Order: entity object
42
:HomePage :Book :Order:Customer
enters keyword
search( )
choose books
The CUSTOMER enters the keyword for a book and clicks the SEARCH button on the personal Home Page
The system displays the matching books on the web Page
The CUSTOMER chooses the desired book and clicks the ADD TO SHOPPING CART button on the web page.
The system adds the book into the CUSTOMER’s Order table in the database.
Order Order booksbooks
clickSearch( )
displayMatch( )
clickAdd()
<<create>>)
addBook( )
43
Use Case: Check-outMain flow of events
1. The CUSTOMER clicks the Check out button on the Home Page2. The system displays the books in the ORDER table of the
CUSTOMER on the web Page.3. The CUSTOMER checks the order list for any inconsistency. If
nothing was found, CUSTOMER clicks the PROCEED button. 4. The system displays the Invoice page.5. The Customer enters the relevant credit card information and clicks
OK. 6. The system checks that the credit card is valid. Then, the system
displays the Delivery Details page.
7. The CUSTOMER chooses destination for delivery, along with delivery options. Then, he/she clicks the PROCEED button. 8. The system will display the check-out information for confirmation.7. The CUSTOMER checks that all information is correct and then clicks
the OK button. 8. The system sends a confirmation via CUSTOMER’s e-mail.
Objects: - Home Page, Invoice Page and Delivery Page: boundary objects Customer and Order: entity objects
44
:HomePage :Customer:Customer
clickCheckOut( )retrieve()
display( )
:Order
display( )
verify info
clickProceed( )
:InvoicePage
clickOK() validate( )
:DeliveryPage
display( )
enter credit card info
clickOK()
choose destination
display()
confirm and clickOK ()
45
Use case: Sell used booksMain flow of events: -
1. The CUSTOMER clicks the Sell Used Books button on the Home Page.
2. The system displays the sell used books web page.3. The CUSTOMER enters the required information on the used
books that he/she wants to sell. 4. The CUSTOMER clicks the SEND button on the webpage.5. The system displays a confirmation page listing the information
that the CUSTOMER has entered. 6. The CUSTOMER checks that the information displayed are
accurate. If yes, the CUSTOMER clicks the OK button on the web page.7. The system updates the USED BOOKS table in the database.
Objects:Home Page, Used Books Page and Confirmation Page: boundary
objectsCustomer and Used Books: entity objects
46
:HomePage :UsedBooksPage
:Customer:Customer
clickUsedBooks( )
display( )
enter book info
clickSend( )
verify info
Sell used Sell used booksbooks
:UsedBook:ConfPage
display( )
clickOK( )
add( )
add( )
47
Use case: ReviewMain flow of events: -
1. The CUSTOMER enters the keyword to search for a book and then
clicks the SEARCH button on the Personal Web Page.2. The system displays the matching books on the web Page.3. The CUSTOMER checks for the desired book and clicks on the chosen book icon. 4. The system displays the book’s detail in the Book Detail web
page.5. The CUSTOMER clicks the REVIEW button on the web page.6. The system displays the Review Book web page.7. The CUSTOMER clicks on the desired star button and the click
the OK button on the web page.8. The system calculates the overall rating of the book and
updates the Book table in the database.9. The system displays the Book Detail web pages that have
been updated.
Objects?Diagram?
18-49
Commonly Used UML Diagrams The most commonly used UML diagrams are:Use case diagram, describing how the system is used.The starting point for UML modeling.
Activity diagram.Each use case may create one activity diagram.
18-50
Commonly Used UML Diagrams
Sequence diagram, showing the sequence of activities and class relationships.Each use case may create one or more sequence diagrams.
A collaboration diagram is an alternative to a sequence diagram.
18-51
Commonly Used UML Diagrams
Class diagram, showing classes and relationships.Sequence diagrams and CRC cards
are used to determine classes.Statechart diagram.
Each class may create a statechart diagram, useful for determining class methods.
Activity ModelingActivity diagrams describe the workflow behavior of a system.
They are typically used for business process modeling, for modeling the logic captured by a single use case or usage scenario, or for modeling the detailed logic of a business rule.
Cont…UML activity diagrams could potentially model the internal logic of a complex operation.
In many ways UML activity diagrams are the object-oriented equivalent of flow charts.
Cont…Activity diagrams do not give detail about how objects behave or how objects collaborate.
Diagrams are read from top to bottom and have branches and forks to describe conditions and parallel activities.
A fork (diverge) is used when multiple activities are occurring at the same time.
18-57
Cont…Activity diagrams show the
sequence of activities in a process, including sequential and parallel activities.
Symbols are used for activities, decisions and so on.
Arrows represent events that connect the activities.
Cont…The diagram above shows a fork after activity1.
This indicates that both activity2 and activity3 are occurring at the same time.
After activity2 there is a branch. The branch describes what activities will take place based on a set of conditions.
Cont…All branches at some point are followed by a merge to indicate the end of the conditional behavior started by that branch.
After the merge all of the parallel activities must be combined by a join before transitioning into the final activity state.
18-63
Creating Activity DiagramsAsk what happens first, second, and so on.
Determine if the activities happen in sequence or parallel.
Examine all the scenarios for a use case.
18-64
SwimlanesIncluded on activity diagrams to
show partitioningShow which activities:
Occur on a browserOccur on a serverHappen on a mainframeAre done by external partners
Help to divide tasks among team members
18-65
Swimlane Boundaries When an event crosses swimlane boundaries, data must be transmitted.A Web form is sent to a server.Data are placed into middleware to transmit it between a server and a mainframe.
Data are transmitted to and from an external partner.
66
More on Activity Diagrams An activity diagram is like a state diagram.
Except most transitions are caused by internal events, such as the completion of a computation.
An activity diagramCan be used to understand the flow of work
that an object or component performs. Can also be used to visualize the
interrelation and interaction between different use cases.
Is most often associated with several classes.
69
Representing concurrencyConcurrency is shown using forks,
joins and rendezvous (Convergent). A fork has one incoming transition and
multiple outgoing transitions. The execution splits into two
concurrent threads.A rendezvous has multiple incoming and
multiple outgoing transitions. Once all the incoming transitions occur
all the outgoing transitions may occur.
70
Representing concurrency A join has multiple incoming transitions
and one outgoing transition. The outgoing transition will be taken
when all incoming transitions have occurred.
The incoming transitions must be triggered in separate threads.
If one incoming transition occurs, a wait condition occurs at the join until the other transitions occur.
71
SwimlanesActivity diagrams are most often
associated with several classes. The partition of activities among the existing classes can be explicitly shown using swimlanes.
Final RemarkOther diagrams (will be covered in their
respective chapters) State chart/ ActivityCollaboration/ Sequence Component Deployment
Exercises(1) Sketch a sequence diagram for the “normal” operation
of an ATM (i.e. a customer inserts the card, enters his/her PIN, enters the amount, takes the card, and takes the money). The sequence diagram should show the interaction between the different components of the ATM.
(2) Online customer can browse or search items, view specific item, add it to shopping cart, view and update shopping cart, do checkout. User can view shopping cart at any time. Design an activity diagram for the above scenario.
(3) The sequence diagram below (see slide no 78) models an interaction that occurs when a customer orders a product . After carefully reviewing the diagram, explain in English what is happening in the interaction.
Exercise 2The user chooses to add a new appointment in the UI.
The UI notices which part of the calendar is active and pops up an Add Appointment window for that date and time. The user enters the necessary information about the appointment's name, location, start and end times. The UI will prevent the user from entering an appointment that has invalid information, such as an empty name or negative duration. The calendar records the new appointment in the user's list of appointments.
Any reminder selected by the user is added to the list of reminders. If the user already has an appointment at that time, the user is shown a warning message and asked to choose an available time or replace the previous appointment. If the user enters an appointment with the same name and duration as an existing group meeting, the calendar asks the user whether he/she intended to join that group meeting instead. If so, the user is added to that group meeting's list of participants.