<<

UML Activity , State-Machine Diagrams and Modelling Lecture # 2

Department of Science and Technology University of Bedfordshire

Written by David Goodwin, based on the book Applying UML and Patterns (3rd ed.) by . Larman (2005).

Modelling and Simulation, 2012 UML Activity Outline Diagrams, State-Machine Diagrams and Modelling

Activity Diagrams

Introduction Activity Activity Diagrams - notation Diagrams Introduction How to apply diagrams Activity Diagrams - notation Guidelines How to apply activity diagrams Guidelines State-Machine Diagrams State-Machine Diagrams Introduction Introduction State-Machine State-Machine Diagrams - notation Diagrams - How to apply state-machine diagrams notation How to apply state-machine diagrams Further Examples Further Examples UML Activity Diagrams, State-Machine Diagrams and Modelling

Activity Diagrams Introduction Activity Diagrams Activity Diagrams - notation How to apply activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity What is an Activity ” Diagrams, State-Machine Diagrams and Modelling I An is on of the Behaviour diargams. I Activity modelling is the sequence and conditions for coordinating lower-level behaviours, rather than which classifiers own those behaviours. Activity Diagrams I These are commonly called control flow and object flow Introduction Activity Diagrams models. - notation How to apply I The behaviours coordinated by these models can be activity diagrams initiated because other behaviours finish executing, Guidelines State-Machine because objects and data become available, or because Diagrams events occur external to the flow. Introduction State-Machine I A UML Activity Diagram shows sequential and parallel Diagrams - notation activities in a process. How to apply state-machine I Useful for modelling: diagrams I Business processes Further Examples I Workflows I Data flows I Complex algorithms UML Activity Basic UML Activity Diagram notation Diagrams, State-Machine Diagrams and Modelling

Action It does something. There is automatic transition on its completion. A transition Activity (arrows between actions) supports modelling of Diagrams Introduction control flow. Activity Diagrams - notation Fork One incoming transition, and multiple outgoing How to apply activity diagrams parallel transitions and/or object flows. Guidelines Multiple incoming transitions and/or object State-Machine Join Diagrams flows; one outgoing transitions. The outgoing Introduction State-Machine continuation does not happen until all the Diagrams - notation inputs arrive from all flows. How to apply state-machine Object Node An object produced or used by actions. This diagrams Further allows us to model data flows or object flows. Examples UML Activity Initial and Final Nodes Diagrams, State-Machine Diagrams and Modelling I Initial Node:

I An initial is a control node at which flow starts when the activity is invoked.

I An activity may have more than one initial node. Activity Diagrams Introduction Activity Diagrams - notation How to apply activity diagrams Guidelines

State-Machine Diagrams I Final Node: Introduction State-Machine I An activity may have more than one activity final node; Diagrams - the first one reached stops all flows in the activity. notation How to apply state-machine diagrams

Further Examples UML Activity Action Diagrams, State-Machine Diagrams and Modelling I Action:

I An action represents a single step within an activity that is not further decomposed within the activity. I An activity represents a behaviour that is composed of Activity individual elements that are actions. Diagrams Introduction I An action is simple from the point of view of the Activity Diagrams activity containing it, but may be complex in its effect - notation How to apply and not be atomic. activity diagrams I An activity can be reused in many places, whereas an Guidelines instance of an action is only used once at a particular State-Machine point in an activity. Diagrams Introduction I An action will not begin execution until all of its input State-Machine Diagrams - conditions are satisfied. notation How to apply state-machine diagrams

Further Examples UML Activity Merge and Decision Nodes Diagrams, State-Machine Diagrams and Modelling I Merge Node:

I A merge node is a control node that brings together multiple alternate flows. Activity I It is not used to synchronize concurrent flows but to Diagrams accept one among several alternate flows. Introduction I Activity Diagrams A merge node has multiple incoming edges and a single - notation outgoing edge. How to apply activity diagrams I Decision Node: Guidelines

I A decision node accepts tokens on an incoming edge State-Machine Diagrams and presents them to multiple outgoing edges. Introduction I Which of the edges is actually traversed depends on the State-Machine Diagrams - evaluation of the guards on the outgoing edges. notation How to apply state-machine diagrams

Further Examples UML Activity Join and Fork Nodes Diagrams, State-Machine Diagrams and Modelling I Join Node:

I A join node is a control node that synchronizes multiple flows. I A join node has multiple incoming edges and one Activity outgoing edge. Diagrams Introduction I Fork Node: Activity Diagrams - notation I A fork node is a control node that splits a flow into How to apply multiple concurrent flows. activity diagrams Guidelines I A fork node has one incoming edge and multiple State-Machine outgoing edges. Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Object Node Diagrams, State-Machine Diagrams and Modelling

I Object Node:

I An object node is an activity node that indicates an Activity instance of a particular classifier, possibly in a particular Diagrams state, may be available at a particular point in the Introduction Activity Diagrams activity. - notation How to apply I Object nodes can be used in a variety of ways, activity diagrams depending on where objects are flowing from and to. Guidelines State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Note Diagrams, State-Machine Diagrams and Modelling

I Note: Activity Diagrams I A note (comment) gives the ability to attach various Introduction remarks to elements. Activity Diagrams - notation I A comment carries no semantic force, but may contain How to apply information that is useful to a modeller. activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Buisness Process Modelling Diagrams, State-Machine Diagrams and Modelling

Activity I Example: Parcel shipping Diagrams Introduction I The process of shipping a parcel is non-trivial; there are Activity Diagrams many parties involived (customer, driver,. . . ) and many - notation How to apply steps. activity diagrams I The process can be captured by a diagram, Guidelines but activity diagrams are great example of “a picture State-Machine Diagrams being worth a thousand words”. Introduction I Object nodes are useful for illustrating what is moving State-Machine Diagrams - around. notation How to apply state-machine diagrams

Further Examples UML Activity Activity Diagram Parcel shipping Diagrams, State-Machine Diagrams and Modelling

Activity Diagrams Introduction Activity Diagrams - notation How to apply activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Guideline for Activity Modelling Diagrams, State-Machine Diagrams and Modelling

I The technique proves most valuable for very complex Activity processes, usually involving many parties. Diagrams Introduction I On a first overview “level 0” diagram, keep all the Activity Diagrams - notation actions at a very high level of abstraction, so that the How to apply activity diagrams diagram is short. Then expand details in sub-diagrams Guidelines

at the “level 1” level,. . . etc. State-Machine Diagrams I Try to make the level of abstraction of action nodes Introduction State-Machine roughly equal withn a diagram (Very different levels of Diagrams - abstraction might be a node labelled “Deliver Order” notation How to apply state-machine and a node labelled “Calculate Tax”). diagrams

Further Examples UML Activity Diagrams, State-Machine Diagrams and Modelling

Activity Diagrams Introduction State-Machine Activity Diagrams - notation How to apply Diagrams activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity What is a State-Machine Diagram” Diagrams, State-Machine Diagrams and Modelling

I State-Machine Diagrams specify state machines.

I As with Activity Diagrams, UML State-Machine Diagrams show a dynamic flow. Activity Diagrams I The UML includes notation to illustrate events and Introduction states of things (transactions, Use Cases, Activity Diagrams - notation people,. . . etc.). How to apply activity diagrams I An is a significant or noteworthy occurence e.g. a Guidelines

telephone receiver is taken off the hook. State-Machine Diagrams I A state is the condition of an object at a moment in Introduction time e.g. a telephone is in the state of being “idle” State-Machine Diagrams - after the receiver is place on the hook and until it is notation taken off the hook. How to apply state-machine I A transition is a relationship between two states that diagrams indicates when an event occurs e.g. when the event “off Further hook” occurs, transition the telephone from “idle” to Examples “active” state. UML Activity Initial Pseudo State and Final State Diagrams, State-Machine Diagrams and Modelling I Initial Pseudo State:

I An initial pseudostate represents a default vertex that is the source for a single transition to the default state.

I There can be at most one initial vertex in a region. Activity Diagrams Introduction Activity Diagrams - notation How to apply activity diagrams Guidelines

State-Machine Diagrams I Final State: Introduction State-Machine I A special kind of state signifying that the enclosing Diagrams - notation region is completed, leading to the entire state machine How to apply state-machine being completed. diagrams

Further Examples UML Activity State Diagrams, State-Machine Diagrams and Modelling I State:

I A state models a situation during which some (usually implicit) invariant condition holds. I The invariant may represent a static situation such as Activity Diagrams an object waiting for some external event to occur. Introduction I However, it can also model dynamic conditions such as Activity Diagrams - notation the process of performing some behaviour (i.e., the How to apply model element under consideration enters the state activity diagrams Guidelines when the behaviour commences and leaves it as soon as State-Machine the behaviour is completed). Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Choice Diagrams, State-Machine Diagrams and Modelling

I Choice:

I choice vertices result in the dynamic evaluation of the Activity guards of the triggers of its outgoing transitions. Diagrams Introduction I It allows splitting of transitions into multiple outgoing Activity Diagrams paths. - notation How to apply I If more than one of the guards evaluates to true, an activity diagrams arbitrary one is selected. If none of the guards evaluates Guidelines to true, then the model is considered ill-formed. (To State-Machine avoid this define one outgoing transition with the Diagrams Introduction predefined else guard for every choice vertex). State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Join and Fork Diagrams, State-Machine Diagrams and I Join: Modelling I Join vertices serve to merge several transitions emanating from source vertices in different orthogonal regions. Activity I The transitions entering a join vertex cannot have Diagrams guards or triggers. Introduction Activity Diagrams I Fork: - notation I Fork vertices serve to split an incoming transition into How to apply activity diagrams two or more transitions terminating on orthogonal Guidelines

target vertices. State-Machine I The segments outgoing from a fork vertex must not Diagrams have guards or triggers. Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Transition Diagrams, State-Machine Diagrams and Modelling I Transition:

I A transition is a directed relationship between a source vertex and a target vertex. I It may be part of a compound transition, which takes Activity the state machine from one state configuration to Diagrams another, representing the complete response of the state Introduction Activity Diagrams machine to an occurrence of an event of a particular - notation How to apply type. activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Note Diagrams, State-Machine Diagrams and Modelling

I Note: Activity Diagrams I A note (comment) gives the ability to attach various Introduction remarks to elements. Activity Diagrams - notation I A comment carries no semantic force, but may contain How to apply information that is useful to a modeller. activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity State-Independent and State Diagrams, State-Machine Diagrams and Dependent Objects Modelling

Activity Diagrams If an object always responds the same way to an event, Introduction I Activity Diagrams then it is considered state-independent with respect to - notation How to apply that event. activity diagrams Guidelines

I If for all events of interest an object always reacts the State-Machine same way, it is a state-independent object. Diagrams Introduction State-Machine I By contrast state-dependent objects react differently Diagrams - to events depending on their state. notation How to apply state-machine diagrams

Further Examples UML Activity State-Independent and State Diagrams, State-Machine Diagrams and Dependent Objects Modelling

Activity I Business information systems have few state-dependent Diagrams Introduction classes, so it is not helpful to apply a state machine Activity Diagrams - notation modelling. How to apply activity diagrams I Process control, device control, protocol handlers, and Guidelines

telecommunication domains often have many State-Machine state-dependent objects; state machine modelling would Diagrams be useful in these cases. Introduction State-Machine Diagrams - I e.g. a telephone is state-dependent; the phone’s notation reaction to pushing a particular button depends on the How to apply state-machine current mode of the phone (off hook, engaged,. . . etc). diagrams Further Examples UML Activity Example: Booking a psychiatrist Diagrams, State-Machine Diagrams and appointment Modelling

Activity Diagrams Introduction Activity Diagrams - notation How to apply activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Diagrams, State-Machine Diagrams and Modelling

Activity Diagrams Introduction Activity Diagrams Further Examples - notation How to apply activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Recycling machine - deposit items Diagrams, State-Machine Diagrams and Modelling

I When a customer returns his/her first deposit item, the

machine will register the customer. Activity Diagrams I The machine will measure the returned item. The Introduction measurements are used to determine what kind of can, Activity Diagrams - notation bottle or crate has been returned. If acceptable, the How to apply activity diagrams total number of items and the total value of this type Guidelines returned by the customer increments. State-Machine Diagrams I When the customer presses the receipt button, the Introduction State-Machine printer prints the date. The total number of items he Diagrams - notation returned and the lump sum is calculated. The How to apply state-machine followings are printed out: customer number, number diagrams returned, deposit value, total of this type and lump sum. Further Examples UML Activity Recycling Activity Diagrams Diagrams, State-Machine Diagrams and Modelling

Activity Diagrams Introduction Activity Diagrams - notation How to apply activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity Recycling machine - changing Diagrams, State-Machine Diagrams and values. . . Modelling

Activity I When an operator changes items’ values, the machine Diagrams should first display a menu which contains three Introduction Activity Diagrams options: crate, can and bottle. - notation How to apply I When the operator chooses one option, the machine activity diagrams Guidelines should display the current value of the corresponding State-Machine item and a range in which the value can vary. Diagrams Introduction I If the operator enters a value that is within the range, State-Machine Diagrams - the machine will ask the operator to confirm the notation How to apply change and then update the value of the item stored in state-machine diagrams

the machine. Further Examples UML Activity ATM Use Case Diagrams, State-Machine Diagrams and Modelling

Activity Diagrams Introduction Activity Diagrams - notation How to apply activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity ATM State-machine diagrams Diagrams, State-Machine Diagrams and Modelling

Activity Diagrams Introduction Activity Diagrams - notation How to apply activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity ATM State-machine diagrams Diagrams, State-Machine Diagrams and Modelling

Activity Diagrams Introduction Activity Diagrams - notation How to apply activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples UML Activity ATM State-machine diagrams Diagrams, State-Machine Diagrams and Modelling

Activity Diagrams Introduction Activity Diagrams - notation How to apply activity diagrams Guidelines

State-Machine Diagrams Introduction State-Machine Diagrams - notation How to apply state-machine diagrams

Further Examples