Sei sulla pagina 1di 32

Advanced State Diagrams & Interaction Model

Unit 3: Advanced State Diagrams, Interaction modelling


Syllabus --------7hr
Nested state diagram
Nested states
Signal generalization
Concurrency
A sample state mode
Relation of class and state models
Use case models
Sequence models
Activity models

Explain nested states and nested state diagrams, with example.----10M

Nested state diagram


1. Problem with flat state diagrams
Flat unstructured state diagram are impractical for large problems, because representing an
object with n independent Boolean attribute requires 2n states. By partitioning the state into n
independent sate diagram requires 2n states only. Eg:

Above figure requires n2 transition to connect every state to other state. This can be reduced
to as low as n by using sub diagrams structure.
2. Expanding states
One way to organize a model is by having high level diagram with sub diagrams
expanding certain state. This is like a macro substitution in programming language
A submachine is a state diagram that may be invoked as part of another state diagram
Advanced State Diagrams & Interaction Model

Nested states:
Nested state : a state that shares behaviour from its composite state and adds additional
behaviour of its own.
Composite state: a state that provides shared behaviour for nested states.
Simplify the original complex state diagram.
States with common features and shared behaviors can be grouped or nested
inside composite states.
Composite state (active): labels the outer contour entirely encloses the nested
states.
Composite states are useful for expressing exception and error conditions
In the fig below, The transmission can be in reverse, neutral or forward, if it is in forward, it
can be in first, second or third gear. States first, second and third are the nested states of state
Forward. Each of the nested states receives the outgoing transitions of its composite state.
Selecting N in any forward gear shifts the transition to Neutral state. Selecting F in Neutral
causes a transition to Forward.
Advanced State Diagrams & Interaction Model

What are nested states? Explain with examples / nested states for a phone line.----5M

In the fig. below, All the original states other than Idle are nested states of Active. The
occurence of event onHook in any nested state causes a transition to state Idle. The Active
state is a composite state consisting of nested states DialTone, Dialing,Connecting etc

Signal generalization
You can organize signals into generalization hierarchy with inheritance of signal
attributes.
Ultimately, we can view every actual signal as a leaf on a generalization tree of
signals.
In a state diagram, a received signal triggers transitions that are defined for any
ancestor signal type.
Advanced State Diagrams & Interaction Model

For eg: typing an a would trigger a transition on a signal alphanumeric as well as


key board character.

What is concurrency? Explain the aggregation concurrency, with an example----------


6M

**Concurrency
The state model implicitly supports concurrency among objects.
Objects are autonomous entities that can act and change state independent of one
another.
However objects need not be completely independent and may be subject to shared
constraints that cause some correspondence among their state changes.
1. Aggregation concurrency
State diagram for an assembly consist of collection of state diagram, one for each part.
Aggregate state (car) is combined states of all the parts.
Each part undergoes transition in parallel. Aggregation concurrency is the and-
relationship.
The aggregate state is one state from the first diagram, and a state from second
diagram and a state from each other diagram.
Transition for one object can depend on another object being in a given state.
Advanced State Diagrams & Interaction Model

The above figure shows the state of a car as an aggregation of parts


Ignition
Transmission
Accelerator
Brake
The state of the car includes one state from each part. Each part undergoes transitions in
parallel with all the others.
The state diagrams of the parts are dependent. The car will not start unless the transmission is
in neutral-shown by the guard expression Transmission in Neutral on the transition from
Ignition-Off to Ignition-Starting.

Explain aggregation concurrency within an object with an example each.--------8/10M

2.Concurrency within an Object


Objects can be partitioned into subsets of attributes or links. Each of the partitioned
subset has its own subdiagram.
Advanced State Diagrams & Interaction Model

The subdiagrams can be dependent: Same event can cause transition in more than one
subdiagram.
The state of the object comprises one state from each subdiagram.
The UML shows concurrency within an object by partitioning the composite state into regions
with dotted lines
state diagram for the play of bridge rubber.
When a side wins a game ,it becomes vulnerable. The first side to win two games
wins the rubber.
During the play, the state of the rubber consists of one state from each sub diagram.
Both sides are initially in their respective default states not vulnerable.
Each region can independently advance to state Vulnerable when its side wins a
game. When one side wins a second game, a transition occurs to the corresponding
wins cup .
This transition terminates both concurrent regions, because they are part of the same
composite state.

3. synchronization of concurrent activities


Sometimes one object must perform two(or more) activities concurrently.
Object must complete both activities before it can progress to its next state.
Advanced State Diagrams & Interaction Model

After dispensing the cash the machine must not reset itself until the user takes both the
cash & the card.
The user may take them in any order or even simultaneously.
2 concurrent substates becomes active and execute independently.
A transition that forks indicates splitting of control into concurrent parts. The
transition on event ready, splits into two concurrent parts, one to each concurrent sub
diagram.
The UML shoes the explicit merging of concurrent control by a transition with two
or more input arrows and one output arrow, all connected to a small heavy bar(not
shown in the above diagram). A completion transition fires when activity in the
source state is complete The composite concurrent state is complete when each of its
concurrent substrates is complete

Relation of Class and State Models


The class model captures the static structure
The state model expresses the dynamic behavior of objects.
A state is an abstraction of the values and links of an object.
State diagram is a graph whose nodes are states and whose directed arcs are
transitions between states. It describes the behaviour of a system, some part of
a system, or an individual object.
A single object can have different states over time.
State structure is related to class structure
States with common features and shared behaviors can be grouped or nested inside
composite states
We can include 3 sources of concurrency within the class model:
Aggregation concurrency: state diagram for an assembly (Aggregation) is a
collection of state diagram, one for each part.
Concurrency within an object: objects can be partitioned into subsets of attributes or
links. Each of the partitioned subset has its own subdiagram.
Synchronization of concurrent activities: Sometimes one object must perform two(or
more) activities concurrently. Object must complete both activities before it can
progress to its next state.
Advanced State Diagrams & Interaction Model

Each Superclass and subclass has a state diagram and they interact.
If both Has Superclass and subclass has disjoint set of attributes then ---no problem
If both Has Superclass and subclass has same then conflict each other.
The state model of a class is inherited by its subclasses. It inherits both states and
transitions.
The state diagram of the subclass must concentrate only on the attributes unique to
subclasses.
In Signal hierarchy signals are considered as objects in classes and operation name as
signal name.

INTERACTION MODELING
The class model describes the objects in a system and their relationship.
The state model describes the life cycles of the objects.
The interaction model describes how the objects interact.
The interaction model starts with use cases that are then elaborated with sequence and
activity diagrams
Use case: focuses on functionality of a system- i.e, what a system does for users
Sequence diagrams: shows the object that interact and the time sequence of their
interactions
Activity diagrams: elaborates important processing steps

Use Case models


Actors
A direct external user of a system

1) Not part of the system


2) For example -Traveler, agent, and airline for a travel agency system.
i. Can be a person, devices and other system
An actor has a single well-defined purpose.

Actors are represented in UML as the stick man form.


Advanced State Diagrams & Interaction Model

Use cases

A use case is a coherent piece of functionality that a system can provide by interacting with
actors.

1) A use case involves a sequence of messages among the system and its actors.
2) The UML icon for use cases is an ellipse shape with the name of the use case.

3) For example: A customer actor can buy a beverage from a vending machine. A
repair technician can perform scheduled maintenance on a vending machine.
4) Each use case involves one or more actors as well as the system itself.
5) Error conditions are also part of a use case.
6) A use case brings together all of the behavior relevant to a slice of system functionality

Use case description for Buy a beverage use case from vending machine use case
diagram
Advanced State Diagrams & Interaction Model

Use case diagrams

Use case diagram: a graphical notation for summarizing actors and use cases.

Use case diagram for a vending machine

Draw the use case diagram for vending machine. What are the guidelines needed to be
followed while drawing use case models.-----10M
Advanced State Diagrams & Interaction Model

What are use case models? Give the guidelines for constructing the use case model.---
5M

Guidelines for use case models

1) First determine the system boundary:


System boundary tells about the scope of system
Scope of system tells what system includes and what system must omit.
2) Ensure that actors are focused
all actors should have a single coherent purpose.
Example: consider owner of personal computer. Owner as a single actor can perform
install software, update a database, and send email. These functions have different
impact on the system.
To simplify we can break owner actor into 3 actors: system administrator, database
administrator and computer user.
3) Each use case must provide value to users:
Use case should not be too narrow like Dial a telephone number which is
not a good use case.
Use case should represent complete transaction for example Make a call
which include 3 function call+talking+termination.
4) Relate use cases and actors:
every use case should have at least one actor
every actor should participate in at least one use case.
5) Remember that use cases are informal:
use cases are not a formal mechanism.
Use cases are used to identify and organize system functionality from a user point of
view.
Each use case can be expanded later.
6) Use cases can be structured:
for many large applications use cases can be built out of small fragments using
relationships.
Include Relationship: Incorporate one use case within the behavior sequence of
another use case.
Extend Relationship: Add incremental behavior to a use case.
Advanced State Diagrams & Interaction Model

Consider shopping in a physical bookstore of supermarket:


1. List three actors that are involved in the design of a checkout system. Explain the
relevance of each actor.
2. Take the perspective of a customer and list two use cases. Summarize the purpose of
each use case within a sentence.
3. Prepare a use case diagram for physical bookstore checkout system.

Answer:
1. List three actors that are involved in the design of a checkout system. Explain the
relevance of each actor.
Customer: a person who initiates the purchase of an item.
Cashier: an employee who is authorized to check out purchase at a cash register.
Payment verifier: the remote system that approves use of a credit or debit card.

2. Take the perspective of a customer and list two use cases. Summarize the purpose of
each use case within a sentence.
Purchase items : a customer brings one or more items to the checkout register
and pays for the items.
Return items: the customer brings back items that were previously purchased
and gets a refund.

3. Prepare a use case diagram for physical bookstore checkout system.


Advanced State Diagrams & Interaction Model

Consider an online airline reservation system.


1. List 2 actors. Explain relevance of each actor.
2. One use case is to make a flight reservation. List 4 additional use cases at the
comparable level of abstraction. Summarize the purpose of each use case with a
sentence.
3. Prepare a use case diagram for an airline reservation system.

Answer:

Actor Description:

1. Passenger: A person who initiates online booking of ticket.


2. Agent: An employee who is authorized to use the system - cancel ticket and make
flight schedule update.

Use Case Description:

1. Flight Reservation: Passenger can make flight reservation.


2. Check Flight Status: Passenger can get details about the required flights
3. Make Payment: Passenger can use credit or debit card to book ticket.
4. Cancel Ticket: Agent can use the system to cancel a reservation.
5. Update Flight Schedule: Agent can update real-time flight status, departures and
arrivals, airport delays, and airport information etc.
Advanced State Diagrams & Interaction Model

Few more use case diagram:


Advanced State Diagrams & Interaction Model

Sequence Models
What are sequence models? Describe the 2 kinds of sequence models. Draw the
sequence model for online stock broker system-----6M

The sequence model elaborates the themes of use cases.


Two kinds of sequences models
Scenarios Sequence diagrams
1. Scenarios
A scenario is a sequence of events that occurs during one particular execution of a
system such as for a use case.
A scenario can be displayed as a list of text statement.
The scope of the scenario can vary, i.e it can include all the events or some events in
the system.
A scenario contains messages between objects as well as activities performed by
objects.
The first step of writing a scenario is to identify the objects exchanging messages.
Determine the sender and receiver of each message and sequence of messages.

Fig below shows a Scenario for a session with an online stock broker:
Advanced State Diagrams & Interaction Model

2. Sequence Diagram
Sequence diagram shows the participants in an interaction and the sequence of
messages among them.
A sequence diagram shows the interaction of a system with its actors to perform all or
part of a use case.
Each use case requires one or more sequence diagrams to describe its behavior.
Fig. below shows Sequence diagram for a session with an online stock broker.

thin rectangle shows Focus of control: period of time for an objects execution

vertical line shows Lifeline: period of time during which an object exists

Horizontal arrow shows each message from the sender to the receiver.
Advanced State Diagrams & Interaction Model

Time proceeds from top to bottom

Figure below shows Sequence diagram for a stock quote:

Fig. Below shows Sequence diagram for exception (purchase fails due to insufficient
fund):

Consider shopping in a physical bookstore of supermarket:


Advanced State Diagrams & Interaction Model

1. Prepare a normal scenario for each use case.


2. Prepare exception scenario for each use case.
3. Prepare sequence diagram for each normal scenario
Answer:
1. Prepare a normal scenario for each use case.
Purchase items
Customer brings purchased items to the cash counter
Cashier scans each items
Cashier calculates total by adding tax to the total.
Cashier asks for form of payment with the customer
Customer gives credit card for payment.
Cashier scans card using payment verifier.
Payment verifier shows card is acceptable
Customer signs credit card slip
Return items
Customer brings purchased items to the counter
Shows Receipt for previous purchase
Cashier verifies that the Payment is done in cash
Cashier accepts the items & refunds cash

2. Prepare exception scenario for each use case.


Purchase items
Customer brings purchased items to the cash counter
Cashier scans each items
Item misscans occurs and cashier goes to the item display to get the item price
Return items
Customer brings purchased items to the counter
Customer has No Receipt for previous purchase
No refund (customer is given credit slip)

3. Prepare sequence diagram for each normal scenario


Sequence diagram for a purchase of items
Advanced State Diagrams & Interaction Model

Sequence diagram for a return of items

Guidelines for sequence models


1. Prepare at least one scenario per use case
For each use case in use case diagram prepare at least one scenario that show
sequence of events that occurs during one particular execution of a system.
2. Abstract the scenarios into sequence diagrams:
Convert each scenario into Sequence diagrams and show the participants in an
interaction and the sequence of messages among them.
3. Divide complex interactions:
Break large interactions into their constituent tasks & prepare a sequence diagram for
each of them.
4. Prepare a sequence diagram for each error condition:
Advanced State Diagrams & Interaction Model

Show the system response to the error condition with error condition sequence
diagram.

Mention the guidelines for activity models and sequence models----------5M

Activity Models
An activity diagram shows the sequence of steps that make up a complex process, such as an
algorithm or workflow.
Activity diagrams are most useful during the early stages of designing algorithms and
workflows.
Activity diagram is like a traditional flowchart in that it shows the flow of control
from step to step

Explain activity diagram with the UML notation. Give an example. ----5M

Activity diagram Notation


Each activity diagram has two special states the start state and the stop state.
The start state marks the beginning of the workflow
stop state marks the end
Activity: elongated oval
Arrow: sequencing
Diamond: used to describe decision point
Heavy Synchronization bar: splitting/merging of concurrent threads.

How an activity diagram differs from a traditional flowchart? Give the activity diagram
for stock trade processing.---8M

Activity diagram for stock trade processing


Advanced State Diagrams & Interaction Model

1. Activities
The computational steps of an activity diagram are activities/operations.
The purpose of an activity diagram is to show the steps within a complex
process
Activity run longer & can be interrupted by an event
An unlabeled arrow from one activity to another indicate, first activity must
complete before the second activity can begin.

An activity may be decomposed into finer activities :


ex-execute order activity can be expanded as follows:

2. Branches
Advanced State Diagrams & Interaction Model

If there is more than one successor to an activity, each arrow may be labelled with
a condition in square brackets.
In the case of multiple conditions, only One condition is satisfied
If No condition is satisfied then the diagram is badly formed, to avoid [else]
condition can be added.
Symbol: diamond

3. Initiation and termination


Solid circle with outgoing arrow
Bulls eye with incoming arrow

4. Concurrent activities
o fork of control (Synchronization bar) is used to Split activities into several
Concurrent activities
o Combined into single activity using merge of control
o Fork of control:

5. Executable activity diagrams


Activity diagram can show progression of control during execution using activity
token.
In the case of Condition in activity only one successor gets activity token
In the case of concurrent activities, Multiple token is used for concurrent
activities.

6. Guidelines
1. Dont misuse activity diagrams:
o Activity diagrams are intended to elaborate use case & sequence models
o Developer can study algorithms & workflow but never use for Developing
software.
2. Level diagrams:
o activities on a diagram should be at a consistent level of detail.
o Place additional detail for an activity in a separate diagram.
3. Be careful with branches & conditions:
Advanced State Diagrams & Interaction Model

o If there is more than one successor to an activity, each arrow may be


labelled with a condition in square brackets.
o In the case of multiple conditions, only One condition is satisfied
o If No condition is satisfied then the diagram is badly formed, to avoid
[else] condition can be added.
4. Be careful with concurrent activities:
o fork of control (Synchronization bar) is used to Split activities into several
Concurrent activities
o concurrency means that the activities can complete in any order
o Before a merge can happen, all inputs activities must be first complete.
5. Consider executable activity diagrams:
o Activity diagram can show progression of control during execution using
activity token.
o Executable activity diagrams can help developers understand their systems
better. It is helpful for end users who want to follow the progression of a
process.
o In the case of Condition in activity only one successor gets activity token
o In the case of concurrent activities, multiple token is used for concurrent
activities.

Prepare an activity diagram for computing a restaurant bill. There should be a charge
for each delivered item. The total amount should be subject to tax. There is a service
charge of 18% for groups of six or more and give gratuity for smaller groups. Any
coupons and gift certificates submitted by the customer should be subtracted.
Advanced State Diagrams & Interaction Model

ADVANCED INTERACTION MODELING


Use Case Relationships
Independent use cases are sufficient for simplex applications.
Complex use cases can be built from smaller pieces with the include, extend &
generalization relationships.
1. Include Relationship
1) Include relationship incorporates one use case within the behavior sequence of
another use case.
2) An included use case is like a subroutine.
3) The UML notation is a dashed arrow from the including use case(base) to the
included use case. The keyword <<include>> annotates the arrow.
4) In online stock brokerage system, part of establishing a secure session is
validating the user password.
5) Here the base use case is linked to a mandatory use case. There is a tight
coupling between base and included use case

2. Extend relationship
1) Extend relationship adds incremental behavior to a use case.
2) In UML modeling, you can use an extend relationship to specify that one use
case (extension) extends the behavior of another use case (base)
3) The UML notation is a dashed arrow from the extension use case to the base
use case. The keyword <<extend>> annotates the arrow.
4) <<extend>> is a way of inserting new behavior into an existing use case.
5) Its like connecting an optional use case to a base use case. There is a loose
coupling between the base and extended use case.

The brokerage system adds 3 capabilities: buying a stock on margin, selling a


stock and placing a limit on the transaction price.

Trade stocks: used for purchase of stock with cash in hand.


Advanced State Diagrams & Interaction Model

Margin trading: use case gives loan for purchase when No sufficient
cash.
Short sale: allows borrowing the share & immediately sell them when
sufficient cash is available.
Limit order/ market order use case can be used when buying / selling
stock.

3. Generalization
o Parent use case gives general behavior sequence. It includes behavior common
to one or more use cases.
o Child use case inherits features from their parent use case. It can add new
features.
o Child use case can override inherited features.
o The UML convention: arrow with its tail on the child use case and a triangular
arrowhead on the parent use case, the same notation that is used for classes.
o Online stock brokerage system might specialize the general use case make
trade into the child use cases trade bonds, trade stocks and trade options.

4. Combinations of use case relationships

Briefly discuss use case relationships and draw the use case diagram of stock broker
system-----8M
Advanced State Diagrams & Interaction Model

Use case diagram for a Stock brokerage system

The secure session use case includes the behavior of manage accounts, make
trade validate password use cases.
Make trade is an abstract parent with the children-trade bonds, trade stocks
and trade options.
The make trade also includes the behavior of validate password.
The use case margin trading extends both trade bonds and trade stocks.
Use case limit order extends abstract use case make trade i.e. limit orders
apply to trading bonds, stocks and options.
The customer actor connects only the secure session use case.
The securities exchange use case connects to the make trade use case. This
actor does not initiate the use case but it is invoked during execution.

5. Guidelines for use case relationships


1) Use case generalization:
Parent use case gives general behavior sequence. It includes behavior
common to one or more use cases.
child use case inherit features from their parent use case. It adds new
features.
Advanced State Diagrams & Interaction Model

2) Use case inclusion:


Include relationship incorporates one use case within the behavior sequence
of another use case.

3) Use case extension:


Extend relationship adds incremental behavior to a use case.

4) Include vs. extend relationship:


Both factors out the behavior into small pieces.
The include relationship: include behavior is a necessary part of a
configured system.
Extended relationship : system without the added behavior would be
meaningful.

Consider the Purchase of gasoline from an electronic gasoline pump.

Prepare a use case diagram. Normally the customer pays cash for a gas purchase. Add
extend relationship to handle the incremental behaviour of paying by credit card
outside/ paying by credit card inside. Add include relationship to represent the optional
purchase of a car wash.
Advanced State Diagrams & Interaction Model

List & explain relevance of each actor


Summarize the purpose of each use case within a sentence.

Answer:

List & explain relevance of each actor

Customer: a person who initiates the purchase of gas

Cashier: a person who take care of manual credit card payments & monitor sale

Summarize the purpose of each use case within a sentence.

Purchase gas: perform function of obtaining gas & payment using cash

Purchase car wash: perform function of purchase car wash & payment using cash

Pay credit card outside: used for making payment which is directly handled by gas
system

Pay credit card inside: used for making payment which is manually handled by
cashier

Procedural sequence models


1) Sequence diagram with passive objects
Most objects are passive
Advanced State Diagrams & Interaction Model

Passive objects do not have their own threads of control


A passive object is not activated until it has been called.
Once the execution of an operation completes & control returns to the caller,
the passive object becomes inactive.
thin rectangle (activation/ focus of control) is Period of time for an objects
execution where Call of method is processed
Lifeline: Dashed line is used to show that object exists but they are inactive
Fig below shows Compute commission for stock brokerage system using passive
objects. Fig shows procedural call and return of procedure.
Transaction passive object get computecommission() procedural call.
Transaction object calls customertable object in order to calculate service
level.
Transaction object calls ratetable object to calculate commission.
Finally, commission is returned to Transaction object.

2) Sequence diagram with transient objects


Transient object : An object that is not saved to permanent storage
Doubled activation rectangle shows recursive operation.
Symbol X (large X) is placed at the head of call arrow to show object is
destroyed.
ObjectA is an active object that initiates an operation.
ObjectB is a passive object that exists during the entire time, but it is not
active for the whole time.
ObjectBs : During part of the time, it performs a recursive operation
operationE(m,n) within operationE(c,d), as shown by the doubled activation
rectangle between the call by ObjectC on operationE & the return of the result
value.
Advanced State Diagrams & Interaction Model

ObjectC is created & destroyed during the time shown on the diagram, so its
lifeline does not span the whole diagram. It is a transient object.

3) Guidelines for Procedural Sequence Models


Active vs. passive objects:
Passive objects do not have their own threads of control
Active objects have their own threads of control
Most objects are passive & lack their own thread of control.
A passive object is not activated until it has been called.
Once the execution of an operation completes & control returns to the caller,
the passive object becomes inactive.

Advanced features:
Be selective in using advanced features.
Create active & passive as necessary.
Show the implementation details for difficult and important sequence
diagrams.

(**)Special constructs for activity models


What is an activity diagram? Explain the special constructs for activity model.10M

Activity Diagrams have additional notation that is useful for large & complex applications.
1. Sending & receiving signals:
A signal represents one way communication between objects.
A signal send is modeled on an activity diagram as a convex pentagon labeled
with the name of the signal that is sent.
There is no action associated with this state, all it does is send the signal.
Advanced State Diagrams & Interaction Model

You can draw a dashed arrow from the signal send to the object that receives
the signal.
A signal receipt is modeled with a concave pentagon labeled with the name
of the signal that is received.
The signal receipt is just a state with no actions it merely receives the signal.

Consider a workstation that is turned on. It goes through a boot sequence and then
requests that the user log in.
After the entry of password, the workstation queries the network to validate the user.
Upon validation, the workstation finishes its startup process.

What do you mean by a swimlane? Explain briefly an activity diagram with


swimlanes for servicing an airplane.

2. Swimlanes
Swimlanes is a column in an activity diagram that shows the person or
organization that perform activities.
The flight attendant must clean the thrash, the ground crew must add fuel, and
catering must load food and drink before the plane is serviced and ready for its
next flight.
Each swimlane shows which organization is responsible for an activity the
marketing department, the manufacturing department, and the delivery
department etc.
Each column in activity diagram is a swimlane
Lines across swimlane boundaries show interactions among different
organizations.
Advanced State Diagrams & Interaction Model

3. Object flows
An object flow shows how objects are input to or output from the activities.
Input/ output arrow shows control flow of objects
The same object may be input to or an output from several activities.
The same object may go through different states during the execution of activity
diagram.
The UML shows an object value in a particular state by placing the state name in
square brackets following the object name.
An airplane goes through several states as it leaves the gate, flies and then lands
again.

Potrebbero piacerti anche