    <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 Relationships and Associations, Aggregation and
Composition</title>
        <link>https://members.accu.org/index.php/journals/551</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>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">Overload Journal #30 - Feb 1999 + Design of applications and programs</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/journals/">All</a>

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

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

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c174/">30</a>
                    (11)
<br />

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

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

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

                                            <a href="https://members.accu.org/index.php/journals/c174-67/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c174+67/">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 Relationships and Associations, Aggregation and
Composition</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 26 February 1999 16:50:52 +00:00 or Fri, 26 February 1999 16:50:52 +00: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>The distinction between normal associations, aggregation and
composition may not initially seem too complicated, but delving
deeper into the definitions the UML presents and the complexities
of software systems can muddy the waters. The choice you make can
easily confuse those reading your diagrams unless the basis of your
selection is made clear. The definitions of the terms are often
interpreted quite subjectively, and the effect of change on a
system, or in the conceptual model of one, can make earlier
interpretations ambiguous.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e23" id="d0e23"></a>Definition</h2>
</div>
<p>The following definitions are taken from the UML 1.1
documentation [<a href="#UML">UML</a>].</p>
<div class="variablelist">
<dl>
<dt><span class="term">aggregation</span></dt>
<dd>
<p>A special form of association that specifies a whole-part
relationship between the aggregate (whole) and a component
part.</p>
</dd>
<dt><span class="term">composition</span></dt>
<dd>
<p>A form of aggregation with strong ownership and coincident
lifetime as part of the whole. Parts with non-fixed multiplicity
may be created after the composite itself, but once created they
live and die with it (i.e., they share lifetimes). Such parts can
also be explicitly removed before the death of the composite.
Composition may be recursive.</p>
</dd>
</dl>
</div>
<p>The definitions above seem fairly technical and watertight. The
grey areas begin to appear when you start using them in practice.
You can then find that the multiple requirements on composite
relationships preclude them from an awful lot of cases where they
might initially seem appropriate. If you look up aggregation and
composition in a dictionary, you will see why - in non-technical
usage these words are often almost interchangeable.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e46" id="d0e46"></a>Examples</h2>
</div>
<p>Some 'common sense' examples of aggregations could perhaps
include a team being an aggregate of its players, a village of its
inhabitants, a company of its workforce or a society and its
membership. (The example in my earlier article was a box of
paperclips and its contents [<a href="#Blundell">Blundell</a>].)
These are all examples of whole-part, or 'has-a' [4],
relationships, and could be modelled using aggregation.</p>
<div class="figure"><a name="d0e54" id="d0e54"></a>
<div class="mediaobject c2"><img src=
"/var/uploads/journals/resources/uml%20association%20aggregation%20and%20composition.png"
align="middle" alt=
"association, aggregation and composition."></div>
<p class="title c3">Figure 1. association, aggregation and
composition.</p>
</div>
<p>Similarly, some common sense examples of compositions could be a
person and their limbs, heart, brain, and so forth, a stadium and
its pitch and seats, a wall and the bricks from which it is built,
and so on. In each of these cases, the composite is composed of its
parts. You could consider writing a class diagram for the composite
showing the parts as attributes. The attribute notation denotes
composition, and so this would seem to make sense.</p>
<div class="figure"><a name="d0e62" id="d0e62"></a>
<div class="mediaobject c2"><img src=
"/var/uploads/journals/resources/uml%20attribute%20imply%20a%20composition%20association.png"
align="middle" alt=
"attributes imply a composition association."></div>
<p class="title c3">Figure 2. attributes imply a composition
association.</p>
</div>
<p>On closer examination, however, many of the above examples could
be categorised quite differently.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e70" id="d0e70"></a>Problems with
aggregation</h2>
</div>
<p>There are a few problems with at least one of the above examples
of aggregation. As Martin Fowler states [<a href=
"#Fowler">Fowler</a>], there is dispute at this level even amongst
the gurus. A company and its workforce is either an aggregation or
just a simple association, depending upon who you listen to. Is
this truly a whole-part, or 'has-a,' relationship? I think that the
latest preference of at least some of the UML authors [<a href=
"#Booch">Booch</a>], is to say that this would indeed be an
aggregation, if in part because the company is at a higher
organisational level than its employees. An aggregation
relationship is suitable to document this, as it can be seen as one
basis for a whole-part relationship.</p>
<p>Looking at another example, if a society is disbanded, its
membership details may well become irrelevant and so be destroyed.
However, this coincident lifetime is indicative of the stronger
aggregation form of composition.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e83" id="d0e83"></a>Problems with
composition</h2>
</div>
<p>The problems only get worse for composition. The definition for
composition is quite strict, and involves the following rules:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>whole-part relationship (it is an aggregation)</p>
</li>
<li>
<p>strong (not shared) ownership of part</p>
</li>
<li>
<p>coincident lifetimes of whole and part</p>
</li>
<li>
<p>addition/removal of parts allowed for non-fixed multiplicity</p>
</li>
</ul>
</div>
<p>The first rule is from the definition of an aggregation. A
composition association is an aggregation, and so a composition
must still represent a whole-part relationship.</p>
<p>The second rule concerns the ownership of the parts by the
whole. What happens, for example, if two walls meet, and the bricks
forming the bond at the join are shared between the two walls? Do
we now have one longer wall, or do we have two walls with shared
bricks? A wall is logically composed of its constituent bricks1,
yet we apparently have shared ownership in the joined-wall case,
and this precludes composition, according to the UML at least.</p>
<p>Coincident lifetimes is the third requirement, implying that the
bricks be created when the wall is built and destroyed when the
wall is destroyed, which is not necessarily the case for our wall
example. Furthermore, with the advances in spare-part surgery, a
heart or kidney cannot be considered to have a composition
relationship with their original owner if they can be taken out of
one body and placed in another - a clear case of separate
lifetimes. Even though the body and heart are created together,
they need not be destroyed together. As you can see, the context of
the problem is beginning to influence the choice of association
here. If we are not building a system affected by transplant
issues, then we may be quite happy with a choice of composition.
For other systems such a choice may not be appropriate. One day,
brain transplants may become a reality, and so today's cerebral
composition may be tomorrow's aggregation of axons!</p>
<p>When the multiplicity of the part can be variable, clients are
able to construct parts separately and attach them to the whole
after it is created. Similarly they are allowed to detach them
prior to destruction if necessary, as long as the lifetimes are
still effectively coincident. This clearly opens up some
lifetime-management issues to ensure that newly-created parts are
indeed attached to the appropriate 'whole,' and are also destroyed
after being detached prior to destruction of the whole. They must
not be allowed to be reattached to another object at a later date.
Your wall bricks or stadium seats must be destroyed with the wall
or stadium, and cannot be used again.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e109" id="d0e109"></a>Other
Definitions</h2>
</div>
<p>Some practitioners use convenient rules-of-thumb for deciding
between simple unadorned associations and aggregations, and between
aggregation and full-blown composition. This is something to be
wary of when viewing UML diagrams.</p>
<p>Some feel that the additional information given by these symbols
is insufficient to warrant the ambiguity and confusion, and the
trouble making the decision. They use simple associations for
pretty much all cases, or perhaps use aggregation when something
has a very strong whole-part relationship, possibly with related
lifetimes as well. Others prefer to use aggregation fairly
willy-nilly, ignore the coincident lifetime issues of composition
and just focus on the un-shared ownership at one time (so an object
can be detached and reattached to a different whole, as long as it
isn't owned by more than one whole at a time). This can fit in with
the informal perception of composition as simply the whole
comprising the parts - a temporal definition that encompasses the
whole-part idea and arguably the single ownership issue, but which
is more liberal with the ancestry and ultimate fate of the
parts.</p>
<p>Some draw UML diagrams only fairly close to the implementation
end of development, and use the simple rule of aggregation for
pointers and composition for values (and maybe constant pointer
relationships used instead of values merely for efficiency or other
implementation reasons). This works quite well, because at the
implementation stage you have to start getting precise, and
programming languages often support the technical distinction
between composition and aggregation quite well. With heavy use of
smart-pointers, however, you do have to be clear whether you have
composition of objects from the problem space, or just composition
of the smart pointer objects that manage them.</p>
<p>The advantage of some of these rules is that they can make the
initial decision easier (if not automatic) to make, and so require
less thought. Less thought is a good thing if the problem lies with
the UML definitions. It is definitely a bad thing, however, if the
difficulty arises because of an incomplete understanding of the
system at hand, of the stage of development, of the type of diagram
you are drawing/modifying (conceptual, specification or
implementation), or of the technical differences between the
various types of association. In these latter cases, additional
thought is definitely required to sort out what you are doing!</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e120" id=
"d0e120"></a>Conclusion</h2>
</div>
<p>The main points of agonising over these issues are to ensure
that your diagrams are unambiguous, and that they clearly express
your intent to those reading them, possibly long after they are
drawn (or long after you have moved on). Individual associations
can be marked with a note to explain the semantics intended for
that individual case. Otherwise, a note on a diagram, or set of
diagrams (or even a policy for all the diagrams in a project) can
explain the default rationale behind all association choices,
especially if it is partially at odds with the UML default.</p>
<p>The coincident lifetime issue is often the most problematic
aspect of association selection, and the final choice usually
depends strongly on the context of the model and on the system
under development. Designing a system for change, however, means
that you have to design for uses of the system not considered in
the original specification. This is especially true when designing
components for reuse, when today's composition could technically be
tomorrow's aggregation and next week's simple association.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e127" id=
"d0e127"></a>Postscript</h2>
</div>
<p>By the time you read this, version 1.3 of the UML should be out.
A number of things have changed so far since the original
publication of version 1.1 back in September 1997. Amongst other
changes, there are now additional and modified standard stereotypes
and tagged values for extending the core UML set of artifacts,
particularly for associations. I hope to discuss these changes in a
forthcoming article.</p>
</div>
<div class="bibliography">
<div class="titlepage">
<h2><a name="d0e132" id="d0e132"></a>References</h2>
</div>
<div class="bibliomixed"><a name="UML" id="UML"></a>
<p class="bibliomixed">[UML] <span class="citetitle"><i class=
"citetitle">UML Semantics version 1.1</i></span>, available from
Rational's web-site: <span class="bibliomisc"><a href=
"http://www.rational.com/uml" target=
"_top">www.rational.com/uml</a></span>, September 1997.</p>
</div>
<div class="bibliomixed"><a name="Blundell" id="Blundell"></a>
<p class="bibliomixed">[Blundell] Blundell, R.P., <span class=
"citetitle"><i class="citetitle">An Introduction to the
UML</i></span>, Overload 22 pp 7-10, 1997.</p>
</div>
<div class="bibliomixed"><a name="Fowler" id="Fowler"></a>
<p class="bibliomixed">[Fowler] Fowler, M., <span class=
"citetitle"><i class="citetitle">UML Distilled</i></span>,
Addison-Wesley, 1997.</p>
</div>
<div class="bibliomixed"><a name="Booch" id="Booch"></a>
<p class="bibliomixed">[Booch] Booch, G., et al, <span class=
"citetitle"><i class="citetitle">The Unified Modeling Language User
Guide</i></span>, Addison-Wesley, 1998.</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
