Sequence and Activity Diagram

Outline for today

  • UML 2: UML is a living language
  • Overview of important changes in UML 2
  • Frames and nesting
  • >Activity diagrams
  • Deployment diagrams
  • Sequence diagrams
  • Stereotypes **

  

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 1

Changes in UML 2

  • Frames and nesting
    • Changes in diagram notation:
    • Activity diagram
    • >Deployment diagram
    • Sequence diagram
    • Stereotypes **

  

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 2

  

A U M L m o d e l c o n s i s t s o f e l e m e n t s s u c h a s p a c k a g e s , c l a s s e s , a n d a s s o c i a t i o n s . T h e c o r r e s p o n d i n g U M L d i a g r a m s a r e

g r a p h i c a l r e p r e s e n t a t i o n s o f p a r t s o f t h e U M L m o d e l . U M L d i a g r a m s c o n t a i n g r a p h i c a l e l e m e n t s ( n o d e s c o n n e c t e d b y

p a t h s ) t h a t r e p r e s e n t e l e m e n t s i n t h e U M L m o d e l . A s a n e x a m p l e , t w o a s s o c i a t e d c l a s s e s d e f i n e d i n a p a c k a g e w i l l , i n a

Notation for all UML 2 Diagrams

  d i a g r a m f o r t h e p a c k a g e , b e r e p r e s e n t e d b y t w o c l a s s s y m b o l s a n d a n a s s o c i a t i o n p a t h c o n n e c t i n g t h e s e t w o c l a s s s y m b o l s .

  • Mandatory is now the contents area E a c h d i a g r a m h a s a c o n t e n t s a r e a . A s a n o p t i o n , i t m a y h a v e a f r a m e a n d a h e a d i n g a s s h o w n i n F i g u r e A . 1 .
  • Optional: The contents area can be surrounded with frame and a heading

  < h e a d i n g >

Frame

  < c o n t e n t s a r e a >

F i g u r e A .1

  <heading> ::= [< diagram kind >]<name>[<parameters>] Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 3 T h e f r a m e i s a r e c t a n g l e . T h e f r a m e i s p r i m a r i l y u s e d i n c a s e s w h e r e t h e d i a g r a m m e d e l e m e n t h a s g r a p h i c a l b o r d e r e l e m e n t s , l i k e p o r t s f o r c l a s s e s a n d c o m p o n e n t s ( i n c o n n e c t i o n w i t h c o m p o s i t e s t r u c t u r e s ) , a n d e n t r y / e x i t p o i n t s o n s t a t e m a c h i n e s . I n c a s e s w h e r e n o t n e e d e d , t h e f r a m e m a y b e o m i t t e d a n d i m p l i e d b y t h e b o r d e r o f t h e d i a g r a m a r e a

  

Why are interaction frames abbreviated with “sd”?

Historical: s equence d iagram

  Activity diagram Class diagram Component diagram Interaction diagram state machine diagram Use case diagram

  • The following abbreviations are usually used for diagram frames:
  • act (for activity frames)
  • cmp (for component frames)
  • sd (for interaction frames)
  • stm (for state machine frames)
  • uc (for use case frames)

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 4 Diagram Kinds

Nested Diagrams

  UML 2 supports nested diagrams • e.g. an activity diagram inside a class

  • The frame concept visually groups elements that • belong to one diagram

  Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 5

  • • An activity diagram consists of nodes and edges

  • There are three types of activity nodes
  • Control nodes
  • >Executable nodes
  • Most prominent: Action • Object nodes
  • E.g. a docu
  • • An edge is a directed connection between nodes

  • There are two types of edges
  • Control flow edges
  • Object flow edges

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 6 UML 2 Activity Diagrams

Control Nodes in an Activity Diagram

  • Initial node
  • Final node
  • Activity final node
  • Flow final node
  • Fork node
  • Join node
  • Merge node
  • Decision node

  

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 7

  

Example of a Activity Diagram with a

Frame Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 8

  F ig u r e 1 2 .5 0 - A c ti v i ty n o d e n o ta ti o n

E x a m p l e s

The Activity Diagram without Frame

  T h i s f i g u r e i l l u s t r a t e s t h e f o l l o w i n g k i n d s o f a c t i v i t y n o d e : a c t i o n n o d e s ( e . g . , R e c e i v e O r d e r , F i l l O r d e r ) , o b j e c t n o d e s ( I n v o i c e ) , a n d c o n t r o l n o d e s ( t h e i n i t i a l n o d e b e f o r e R e c e i v e O r d e r , t h e d e c i s i o n n o d e a f t e r R e c e i v e O r d e r , a n d t h e f o r k n o d e a n d J o i n n o d e a r o u n d S h i p O r d e r , m e r g e n o d e b e f o r e C l o s e O r d e r , a n d a c t i v i t y f i n a l a f t e r C l o s e O r d e r ) .

  [ o r d e r r e j e c t e d ] F i l l S h i p

  C l o s e R e c e i v e

  O r d e r O r d e r O r d e r

  O r d e r [ o r d e r a c c e p t e d ]

  S e n d M a k e A c c e p t I n v o i c e P a y m e n t P a y m e n t

  I n v o i c e

  F ig u r e 1 2 .5 1 - A c ti v i ty n o d e e x a m p le (w h e r e th e a r r o w e d l in e s a r e o n ly th e n o n - a c tiv ity n o d e s y m b o l s ) Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 9 R a t io n a l e A c t i v i t y n o d e s a r e i n t r o d u c e d t o p r o v i d e a g e n e r a l c l a s s f o r n o d e s c o n n e c t e d b y a c t i v i t y e d g e s .

  F ig u r e 1 2 .5 0 - A c ti v i ty n o d e n o ta ti o n

E x a m p l e s

Activity Diagram Example

  T h i s f i g u r e i l l u s t r a t e s t h e f o l l o w i n g k i n d s o f a c t i v i t y n o d e : a c t i o n n o d e s ( e . g . , R e c e i v e O r d e r , F i l l O r d e r ) , o b j e c t n o d e s ( I n v o i c e ) , a n d c o n t r o l n o d e s ( t h e i n i t i a l n o d e b e f o r e R e c e i v e O r d e r , t h e d e c i s i o n n o d e a f t e r R e c e i v e O r d e r , a n d t h e f o r k n o d e a n d J o i n n o d e a r o u n d S h i p O r d e r , m e r g e n o d e b e f o r e C l o s e O r d e r , a n d a c t i v i t y f i n a l a f t e r C l o s e O r d e r ) .

Fork Join Merge node node node Initial

  [ o r d e r

  node

  r e j e c t e d ] F i l l S h i p

  C l o s e R e c e i v e

  O r d e r O r d e r O r d e r

  O r d e r [ o r d e r a c c e p t e d ]

Final

  S e n d M a k e A c c e p t

  node

  I n v o i c e P a y m e n t P a y m e n t I n v o i c e

  F ig u r e 1 2 .5 1 - A c ti v i ty n o d e e x a m p le (w h e r e th e a r r o w e d l in e s a r e o n ly th e n o n - a c tiv ity n o d e s y m b o l s ) Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 10 R a t io n a l e A c t i v i t y n o d e s a r e i n t r o d u c e d t o p r o v i d e a g e n e r a l c l a s s f o r n o d e s c o n n e c t e d b y a c t i v i t y e d g e s .

  • • An activity diagram consists of nodes and edges

  • There are three types of activity nodes

   Control nodes

  • Executable nodes
  • Most prominent: Action • Object nodes
  • E.g. a docu
  • • An edge is a directed connection between nodes

  • There are two types of edges
  • Control flow edges
  • Object flow edges

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 11 Activity Diagram: Activity Nodes & Edges

Action Nodes and Object Nodes

  • Action Node • Object Node

  

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 12

  Write Thesis Action Name Thesis Review Thesis Object Name

  F ig u r e 1 2 .5 0 - A c ti v i ty n o d e n o ta ti o n

E x a m p l e s

Activity Diagram Example

  T h i s f i g u r e i l l u s t r a t e s t h e f o l l o w i n g k i n d s o f a c t i v i t y n o d e : a c t i o n n o d e s ( e . g . , R e c e i v e O r d e r , F i l l O r d e r ) , o b j e c t n o d e s ( I n v o i c e ) , a n d c o n t r o l n o d e s ( t h e i n i t i a l n o d e b e f o r e R e c e i v e O r d e r , t h e d e c i s i o n n o d e a f t e r R e c e i v e O r d e r , a n d t h e f o r k n o d e a n d J o i n n o d e a r o u n d S h i p O r d e r , m e r g e n o d e b e f o r e C l o s e O r d e r , a n d a c t i v i t y f i n a l a f t e r C l o s e O r d e r ) .

  [ o r d e r r e j e c t e d ] F i l l S h i p

  C l o s e R e c e i v e

  O r d e r O r d e r O r d e r

  O r d e r [ o r d e r a c c e p t e d ]

  S e n d M a k e A c c e p t I n v o i c e P a y m e n t P a y m e n t

  I n v o i c e

  Action Object node F ig u r e 1 2 .5 1 - A c ti v i ty n o d e e x a m p le (w h e r e th e a r r o w e d l in e s a r e o n ly th e n o n - a c tiv ity n o d e s y m b o l s ) Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 13 R a t io n a l e A c t i v i t y n o d e s a r e i n t r o d u c e d t o p r o v i d e a g e n e r a l c l a s s f o r n o d e s c o n n e c t e d b y a c t i v i t y e d g e s .

  • • An activity diagram consists of nodes and edges

  • There are three types of activity nodes

   Control nodes

   Executable nodes

  • Most prominent: Action

   Object nodes

  • E.g. a document
  • • An edge is a directed connection between nodes

  • There are two types of edges
  • Control flow edges
  • Object flow edges

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 14 Activity Diagram: Activity Nodes & Edges

  F ig u r e 1 2 .5 0 - A c ti v i ty n o d e n o ta ti o n

E x a m p l e s

Activity Diagram Example

  T h i s f i g u r e i l l u s t r a t e s t h e f o l l o w i n g k i n d s o f a c t i v i t y n o d e : a c t i o n n o d e s ( e . g . , R e c e i v e O r d e r , F i l l O r d e r ) , o b j e c t n o d e s ( I n v o i c e ) , a n d c o n t r o l n o d e s ( t h e i n i t i a l n o d e b e f o r e R e c e i v e O r d e r , t h e d e c i s i o n n o d e a f t e r R e c e i v e O r d e r , a n d t h e f o r k n o d e a n d J o i n n o d e a r o u n d S h i p O r d e r , m e r g e n o d e b e f o r e C l o s e O r d e r , a n d a c t i v i t y f i n a l a f t e r C l o s e O r d e r ) .

  [ o r d e r r e j e c t e d ] F i l l S h i p

  C l o s e R e c e i v e

  O r d e r O r d e r O r d e r

  O r d e r [ o r d e r a c c e p t e d ]

Control fow

  S e n d M a k e A c c e p t I n v o i c e P a y m e n t P a y m e n t

  I n v o i c e

  Object F ig u r e 1 2 .5 1 - A c ti v i ty n o d e e x a m p le (w h e r e th e a r r o w e d l in e s a r e o n ly th e n o n - a c tiv ity n o d e s y m b o l s ) fow Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 15 R a t io n a l e A c t i v i t y n o d e s a r e i n t r o d u c e d t o p r o v i d e a g e n e r a l c l a s s f o r n o d e s c o n n e c t e d b y a c t i v i t y e d g e s .

  F ig u r e 1 2 .5 0 - A c ti v i ty n o d e n o ta ti o n

E x a m p l e s

Summary: Activity Diagram Example

  T h i s f i g u r e i l l u s t r a t e s t h e f o l l o w i n g k i n d s o f a c t i v i t y n o d e : a c t i o n n o d e s ( e . g . , R e c e i v e O r d e r , F i l l O r d e r ) , o b j e c t n o d e s ( I n v o i c e ) , a n d c o n t r o l n o d e s ( t h e i n i t i a l n o d e b e f o r e R e c e i v e O r d e r , t h e d e c i s i o n n o d e a f t e r R e c e i v e O r d e r , a n d t h e f o r k n o d e a n d J o i n n o d e a r o u n d S h i p O r d e r , m e r g e n o d e b e f o r e C l o s e O r d e r , a n d a c t i v i t y f i n a l a f t e r C l o s e O r d e r ) .

Fork Join Merge node node node Initial

  [ o r d e r

  node

  r e j e c t e d ] F i l l S h i p

  C l o s e R e c e i v e

  O r d e r O r d e r O r d e r

  O r d e r [ o r d e r a c c e p t e d ]

Control fow

  S e n d M a k e A c c e p t

  node

  I n v o i c e P a y m e n t P a y m e n t I n v o i c e

  Action Object Object node F ig u r e 1 2 .5 1 - A c ti v i ty n o d e e x a m p le (w h e r e th e a r r o w e d l in e s a r e o n ly th e n o n - a c tiv ity n o d e s y m b o l s ) fow Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 16 R a t io n a l e A c t i v i t y n o d e s a r e i n t r o d u c e d t o p r o v i d e a g e n e r a l c l a s s f o r n o d e s c o n n e c t e d b y a c t i v i t y e d g e s .

  • Pin: Abbreviated notation for an object node
  • >Different notations with same semantics
  • Both notations define object flow in an activity

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 17 Activity Diagram: Pins

Outline for today

  • Deployment diagrams
    • Sequence diagrams
    • Profiles, Stereotypes • UML Metamodel

  

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 18

   UML 2: UML is a living language  Overview of important changes in UML 2

   Frames and nesting

   Activity diagrams

C o n s tr a i n ts

  N o a d d i t i o n a l c o n s t r a i n t s

UML 2 Deployment Diagrams S e m a n ti c s

  A d e v i c e m a y b e a n e s t e d e l e m e n t , w h e r e a p h y s i c a l m a c h i n e i s d e c o m p o s e d i n t o i t s e l e m e n t s , e i t h e r t h r o u g h n a m e s p a c e

  • o w n e r s h i p o r t h r o u g h a t t r i b u t e s t h a t a r e t y p e d b y D e v i c e s .

  Two node types:

N o ta ti o n

  Device • A D e v i c e i s n o t a t e d b y a p e r s p e c t i v e v i e w o f a c u b e t a g g e d w i t h t h e k e y w o r d « d e v i c e » . Execution • environment

  « d e v i c e » : A p p S e r v e r : D B S e r v e r

  « d e v i c e » « e x e c u t i o n E n v i r o n m e n t » : D B S e r v e r : J 2 E E S e r v e r

  O r d e r S c h e m a . d d l O r d e r . j a r I t e m S c h e m a . d d l S h o p p i n g C a r t . j a r

  A c c o u n t . j a r P r o d u c t . j a r B a c k O r d e r . j a r S e r v i c e . j a r Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 19 F i g u r e 1 0 .1 4 - N o ta tio n fo r a D e v i c e

Deployment Diagram Changes II

  Artifacts can now manifest any packageable •

  « a r t i f a c t »

  O r d e r .ja r element, not just components Manifestation is shown by a dependency with

  • F ig u r e 1 0 .6 - A n A r ti f a c t i n s ta n c e

  keyword «manifest» « c o m p o n e n t »

  O r d e r « m a n i f e s t » « a r t i f a c t »

  O r d e r .j a r F ig u r e 1 0 .7 - A v is u a l r e p r e s e n ta ti o n o f th e m a n i f e s ta ti o n r e l a tio n s h i p b e tw e e n a r ti f a c ts a n d c o m p o n e n ts Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 20 C h a n g e s f r o m p r e v i o u s U M L T h e f o l l o w i n g c h a n g e s f r o m U M L 1 . x h a v e b e e n m a d e : A r t i f a c t s c a n n o w m a n i f e s t a n y P a c k a g e a b l e E l e m e n t ( n o t j u s t C o m p o n e n t s , a s i n U M L 1 . x ) .

  « d e p lo y m e n t s p e c » « d e p lo y m e n t s p e c »

  O r d e r d e s c . x m l S h o p p in g A p p d e s c .x m l

Deployment Diagram

  • F ig u r e 1 0 .1 2 - D e p l o y m e n tS p e c i f ic a tio n s r e la te d to th e a r tif a c t s th a t th e y p a r a m e te r i z e

  A deployment diagam can have a

  deployment specification « a r t i f a c t »

O r d e r . j a r

  « d e p l o y m e n t s p e c » « d e p l o y » O r d e r d e s c .x m l : A p p S e r v e r Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 21 F ig u r e 1 0 .1 3 - A D e p lo y m e n tS p e c if i c a ti o n f o r a n a r ti fa c t

Sequence Diagram Changes

  New concept of interaction fragments • Before going into detail with interaction • fragments, we cover the concept of an interaction

  

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 22

Interaction

  • An Interaction is a concept providing a basis for interaction diagrams:
  • Sequence diagrams
  • Communication diagrams
  • Interaction overview diagrams

  Timing diagrams • An interaction is a unit of behavior that focuses • on the observable exchange of information between connectable elements.

  • We only focus on the impact of interactions on sequence diagrams

  Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 23

  

Example of an Interaction: Sequence

Diagram Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 24

  • The sequence diagram on the previous slide shows three messages between two anonymous

    lifelines of type User and ACSystem: CodePin,

    CardOut and OK
  • The message CardOut overtakes the message OK in the way that the receiving event occurrences are in the

    opposite order of the sending event occurrences.

  • Such communication may occur when the messages are asynchronous.
  • A fourth message Unlock is sent from the ACSystem to the environment
  • Through a gate with the implicit name out_Unlock.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 25 Explanation for the Previous Slide

  • Interaction Fragment
  • >Is a piece of an interaction
  • Acts like an interaction it
  • Combined Fragment
  • Is a subtype of interaction fragment
  • defines an expression of interaction fragments
  • defined by an interaction operator and corresponding

  interaction operands

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 26 Interaction Fragment

  • • A combined fragment defines an expression of interaction

    fragments. The following operators are allowed in an combined fragment expression:
  • Alt
  • Opt
  • Par
  • Loop
  • Critical
  • Neg
  • >Assert
  • Strict • Seq • Ignore • Consider

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 27 Interaction Operators

Alt and Else Operators

  • The interaction operator alt designates that the

    combined fragment represents a choice of behavior.

  • At most one of the operands will be chosen. The chosen

    operand must have an explicit or implicit guard expression that evaluates to true at this point in the interaction. An implicit true guard is implied if the operand has no guard.
  • The set of traces that defines a choice is the union of the

    (guarded) traces of the operands.
  • • An operand guarded by else designates a guard that is

    the negation of the disjunction of all other guards in the enclosing combined fragment.
  • • If none of the operands has a guard that evaluates to true,

  none of the operands are executed and the remainder of the enclosing interaction fragment is executed.

  Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 28

  

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 29

Example of a Combined Fragment

  • Option: The interaction operator opt designates a

  choice of behavior where either the (sole) operand happens or nothing happens.

  • Break : The interaction operator break represents

  

a breaking scenario: The operand is a scenario

that is performed instead of the remainder of the enclosing interaction fragment.

  • A break operator with a guard is chosen when the guard is true
  • When the guard of the break operand is false, the break

  operand is ignored and the rest of the enclosing interaction fragment is chosen.

  • The choice between a break operand without a guard and the rest of the enclosing interaction fragment is done non-deterministically.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 30 Opt and Break Operators

Parallel and Critical Operator

  Parallel: The interaction operator par designates a

  • parallel merge between the behaviors of the operands

    of a combined fragment.

  The event occurrences of the different operands can be

  • interleaved in any way as long as the ordering imposed by each operand is preserved. A parallel merge defines a set of traces that describes all the
  • ways that event occurrences of the operands may be interleaved.

  Critical: The interaction operator critical designates

  • that the combined fragment represents a critical region.

  The traces of the region cannot be interleaved by other event

  • occurrences (on the Lifelines covered by the region). This

    means that the region is treated atomically by the enclosing fragment.

  Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 31

  Example of a Critical Region

The Operator must make sure to forward a 911-call to the Emergency object

before doing anything else. Normal calls can be freely interleaved. Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 32

  • In this example, time constraints are associated with the duration of a

    Message and the duration between two event occurrences.

  Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Paterns, and Java 33 Time Constraint with Messages