    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: UML Interactions &amp; Collaborations</title>
        <link>https://members.accu.org/index.php/articles/598</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Design of applications and programs + Overload Journal #27 - Aug 1998</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c67/">Design</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c176/">27</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c67-176/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c67+176/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;UML Interactions &amp; Collaborations</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 27 August 1999 18:22:42 +01:00 or Fri, 27 August 1999 18:22:42 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id=
"d0e18"></a>Introduction</h2>
</div>
<p>In earlier articles we have covered a number of techniques for
documenting and designing the static behaviour of systems. We saw
one way of representing dynamic behaviour when we looked at
State-Transition diagrams [<a href="#Blundell98">Blundell98</a>],
but these diagrams only really deal with a single object at a
time.<sup>[<a name="d0e26" href="#ftn.d0e26" id=
"d0e26">1</a>]</sup> This month we shall look at collaborating
objects and their interactions over time. The charts we will use
are useful for documenting real-time systems as well as for
complicated processes involving many calls between the objects
involved.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e30" id=
"d0e30"></a>Interactions</h2>
</div>
<p>Conceptually, objects interact by exchanging <i class=
"firstterm">messages</i>. A message is typically 'sent' using a
normal function call, but can also be sent as an inter-thread or
inter-process signal, or an event triggered by a hardware device or
operating system interrupt such as a timer. An <i class=
"firstterm">interaction</i> is a set of message exchanges that
collectively achieve some purpose, usually one that represents some
higher-level action. In other words, an interaction is the
collection of inter-object messages that produces some outcome.</p>
<p>In system design and documentation, it is a common requirement
to document the (non-trivial) interactions of a system, and there
are two types of <i class="firstterm">Interaction diagram</i> with
which this can be done - <i class="firstterm">Collaboration
diagrams</i> and <i class="firstterm">Sequence diagrams</i>.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e52" id=
"d0e52"></a>Collaborations</h2>
</div>
<p>A <i class="firstterm">collaboration</i> is a set of objects
involved in completing some action or operation, combined with the
interaction that produces the action. The collaboration contains
only those objects that are involved in the action (or actions - a
collaboration can describe several related or even unrelated
operations or interactions).</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e60" id="d0e60"></a>Collaboration
Diagrams</h2>
</div>
<p>Collaboration diagrams document collaborations. Visually, a
collaboration diagram looks like an object diagram, complete with
associations between the objects shown in the normal way. On top of
this diagram are superimposed an ordered set of <i class=
"firstterm">message flow</i> arrows showing the pattern of messages
that form the interaction. A simple example is shown in figure
1.</p>
<div class="figure"><a name="d0e68" id="d0e68"></a>
<div class="mediaobject c2"><img src=
"/var/uploads/journals/resources/blundell_collaboration_diagram.png" align="middle" alt=
"A collaboration diagram showing the creation of a slug in a slug farm, and its ultimate consumption, after fattening, by a hedgehog."></div>
<p class="title c3">Figure 1. A collaboration diagram showing the
creation of a slug in a slug farm, and its ultimate consumption,
after fattening, by a hedgehog.</p>
</div>
<p>A message flow shows the transfer of a message from one object
to another. A short arrow is used to denote a message flow.
Typically, the arrowhead is solid, indicating sequential or nested
operation as is used in normal single-threaded procedural design. A
half stick arrowhead is often used to denote asynchronous calls. If
an object sends a message to itself (to show iteration, for
example) the arrow can follow a self-association line, as shown in
step 2 of the figure (and can optionally be labelled with the
stereotype &laquo;self&raquo;). Each arrow can be labelled with a
set of expressions that show details of the messages, and the
conditions under which the message is sent.</p>
<p>Simple message flows are labelled with a sequence number and a
message name, possibly with a return type. For example:</p>
<div class="informalexample">
<p>1.1.4: ret := process(arg, &hellip;)</p>
</div>
<p>The sequence number is the part before the first colon. Sequence
numbers show the order in which the message flows occur. The number
of decimal points shows the call depth. In the above example, this
message flow is the fourth at the current nesting level, and is
nested three levels deep. An example numbering scheme can be seen
in the figure. After the colon, we have the return value, name of
the message, and argument list for the message.</p>
<p>There are several extensions to this basic syntax. A <i class=
"firstterm">guard condition</i> can be added (in square brackets)
before the <i class="firstterm">sequence number</i> to show a
conditional message. The message is only sent if the condition is
true:</p>
<div class="informalexample">
<p>[t &gt; last] 1.3: update()</p>
</div>
<p>As well as digits, letters can be used in a sequence 'number' to
show concurrent threads. Thus, a step 1.2 could be followed by
1.2.1a and 1.2.1b, showing that it passes control to two
threads.</p>
<p>Before the guard condition, another form of condition can be
added that shows the <i class="firstterm">predecessor</i> of the
message flow. This is a list of sequence numbers of messages
(followed by a forward slash) that must all have occurred before
the current message will fire. This allows threads to be
synchronised by requiring different threads to all have reached
some designated point:</p>
<div class="informalexample">
<p>1.4a,1.2b/ 2: theyveFinished()</p>
</div>
<p>Here, message 2 is only sent after the first thread has sent
message 1.4a, and the second thread has sent 1.2b.</p>
<p>Branches and iteration can be shown by appending a <i class=
"firstterm">recurrence</i> term (in square brackets) after a
sequence number. An example of a branch would be message labels
such as 1.1[t = t0] and 1.1[t &lt; &gt; t0], and the message
actually sent depends upon the value of t. If the recurrence
conditions are mutually exclusive (as here), then a single
procedural branch is suggested. If the conditions overlap,
concurrent sequence numbers can be used to show the start of
multi-threaded processing. Iteration is shown using an asterisk and
an expression showing the details of the iteration, for example
2.5*[i := 0..n-1]. In this example, the labelled message fires n
times in succession.</p>
<p>The <i class="firstterm">lifetime</i> of an object in a
collaboration can be shown using the stereotypes &laquo;new&raquo;,
and &laquo;destroyed&raquo;, with &laquo;transient&raquo; meaning a
combination of the two. Sometimes these are shown as constraints in
curly braces instead of stereotypes. As we shall see later, object
lifetimes can be shown more explicitly on sequence diagrams.</p>
<p>Design patterns are collaborations (plus additional information
such as examples of use, limitations, usage guidelines, etc.), and
as such can be partly documented using collaboration diagrams. Once
a pattern has been documented and named, it can be shown on
diagrams using the dashed-oval representation described in an
earlier article [<a href="#Blundell97">Blundell97</a>], with the
actual objects that enact the pattern bound to the roles within the
pattern definition.</p>
<p>That is pretty much it for collaboration diagrams. A normal
static structure diagram with message flows to show the
interactions that occur.<sup>[<a name="d0e123" href="#ftn.d0e123"
id="d0e123">2</a>]</sup> Collaboration diagrams are useful because
they show not only the sequence details of the interaction, but
also its full context - which objects are involved and how they are
related. The disadvantage of these diagrams is that for complicated
interactions they can become very cluttered and difficult to
interpret.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e127" id="d0e127"></a>Sequence
Diagrams</h2>
</div>
<p>Sequence diagrams are the second type of interaction diagram,
and these primarily show the interaction details, omitting much of
the information about the collaboration. The objects involved in
the interaction are shown, but no relationships are given. To
offset this restriction, however, the time-order of the message
flows and object lifetimes are much more obvious, and very involved
interactions are much simpler to interpret.</p>
<p>A typical sequence diagram has time down the page, and
individual objects laid out across the top of the diagram, as shown
in figure 2. <i class="firstterm">Lifelines</i> for each object are
drawn as vertical dashed lines. The lifeline begins at the top of
the page or at the point that the object is created in the
interaction, if later. The lifeline stops at the bottom of the
diagram, or at the point of a large X where the object is
destroyed, if earlier. Message flows are shown as horizontal
arrows<sup>[<a name="d0e137" href="#ftn.d0e137" id=
"d0e137">3</a>]</sup> from one object to another, and the messages
are laid out in time-order down the diagram. Conditional (or
concurrent) behaviour can be shown using multiple message arrows,
each labelled with a guard condition. Target lifelines can split in
two to show alternative or parallel scenarios, with a recombination
possible further down the page.</p>
<p>A feature known as <i class="firstterm">focus of control</i> can
be added to diagrams to show the intervals over which each object
is 'active' in the sense that it is either processing itself or
waiting for another object to finish processing (sometimes these
two cases are distinguished by shading the box (described next) in
the former case). When an object is active, its lifeline
temporarily becomes a long thin box. Recursive calls are shown by
drawing an additional activation box offset from the main one. The
depth of nesting can be shown by multiple offset boxes if you care
to go to that much effort!</p>
<div class="figure"><a name="d0e146" id="d0e146"></a>
<div class="mediaobject c2"><img src=
"/var/uploads/journals/resources/blundell_sequence_diagram.png" align="middle" alt=
"A sequence diagram corresponding to the collaboration diagram in figure 1. The slug farm, slugs and hedgehogs each have their own thread, so I have shown their focus of control boxes as continuously active (assuming they do other processing in the background), whereas the factory is only active when the create method is called by the farm."></div>
<p class="title c3">Figure 2. A sequence diagram corresponding to
the collaboration diagram in figure 1. The slug farm, slugs and
hedgehogs each have their own thread, so I have shown their focus
of control boxes as continuously active (assuming they do other
processing in the background), whereas the factory is only active
when the create method is called by the farm.</p>
</div>
<p>As with collaboration diagrams, message flows can be labelled
with guard conditions, message name, arguments, etc. Sequence
numbers are usually omitted in single-threaded interactions because
the sequence of messages is shown explicitly by the ordering of the
arrows. In addition, returns from procedure calls can be shown
using dashed return arrows.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e154" id=
"d0e154"></a>Conclusion</h2>
</div>
<p>Over the months we have seen how to document some of the static
and dynamic details of a system. State-Transition diagrams are
useful for describing the behaviour of a single class, but to
document collaborating objects the Sequence and Collaboration
diagrams (collectively called Interaction diagrams) described above
are very handy. Next time I'll go back to the design stage taking a
look at Use Cases and Use Case diagrams, and see how these can be
used to define the scope and behaviour of a system.</p>
</div>
<div class="bibliography">
<div class="titlepage">
<h2><a name="d0e159" id="d0e159"></a>References</h2>
</div>
<div class="bibliomixed"><a name="Blundell98" id="Blundell98"></a>
<p class="bibliomixed">[Blundell98] &quot;UML - State Transition
Diagrams&quot;, Overload 24 pp 2 - 5</p>
</div>
<div class="bibliomixed"><a name="Blundell97" id="Blundell97"></a>
<p class="bibliomixed">[Blundell97] &quot;UML - Objects and Patterns&quot;,
Overload 23 p 6</p>
</div>
</div>
<div class="footnotes"><br>
<hr class="c4" width="100">
<div class="footnote">
<p><sup>[<a name="ftn.d0e26" href="#d0e26" id=
"ftn.d0e26">1</a>]</sup> Although of course that object can be an
aggregation of other objects, or a system or subsystem with
conceptual 'states'.</p>
</div>
<div class="footnote">
<p><sup>[<a name="ftn.d0e123" href="#d0e123" id=
"ftn.d0e123">2</a>]</sup> A few other capabilities include showing
active objects with a heavy border to their rectangular symbol, and
nesting objects within others.</p>
</div>
<div class="footnote">
<p><sup>[<a name="ftn.d0e137" href="#d0e137" id=
"ftn.d0e137">3</a>]</sup> &hellip; in the case of messages that can
be considered to be instantaneous. If there could be a significant
delay in the receipt of the message, and if this delay could mean
the sequence of messages could be interrupted, a downward-slanted
arrow can be used to show this.</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
