Professional Documents
Culture Documents
Whole Part1
Whole Part1
www.elsevier.nl/locate/infsof
Departement Informatique, University of Pau, Avenue de lUniversite, BP 576, 64012, Pau cedex, France
Faculty of Information Technology, University of Technology, P.O. Box 123, Broadway, NSW 2007 Sydney, Australia
Abstract
In object models built according to popular object-oriented formalisms, the commonest relationship types (excluding inheritance) are the
structural relationships of association and of whole-part (often called aggregation). This last type is well known to have no accurately
prescribed semantics. Here, some of the aggregation semantics frequently presented in the literature and sometimes supported in current
object-oriented modelling languages, especially UML, are analysed and criticised. Because of defects, the use of a modelling notation based
on these aggregation semantics is dubious and limited. Moreover, many properties are candidates for characterising the whole-part relationship provided that no redundancy and no inconsistency exist between them. A framework known as cOlOr is then offered by means of a
metamodel in which the Whole-Part metatype inherits from the Structural-Relationship metatype. Defining a specific aggregation semantics
leads then, first, within cOlOr, to the creation of a subtype of the Whole-Part metatype. Next, the behaviour of this last type is extended and/or
restricted in using a constraint-based approach. Such a process is developed particularly for considering Composition in UML and Aggregation in OML more formally, as well as for dealing with domain-dependent aggregation semantics. Since a non-negligible feature of cOlOr is
the availability of a C library that implements the proposed metamodel, some implementation concerns are also briefly discussed.
2001 Elsevier Science B.V. All rights reserved.
Keywords: Object modelling; Structural relationship; Whole-Part relationship; Aggregation
1. Introduction
Relationships in object models express structural dependencies (e.g. associations, aggregations) and behavioural
dependencies (e.g. events, collaborations) between the
objects created from the types linked by these kinds of
relationship. The research results presented in this paper
do not refer to inheritance, but focus on structural dependencies. Specifically, it is shown that the Whole-Part (WP)
relationship differs from the standard notion of object association by using the fact that structural connections between
wholes and parts must be subject to particular and precise
constraints. Unfortunately, this is rarely well defined in
object-oriented methods or in object modelling languages.
As a result, object models are intelligible only with difficulty. In that connection, Lano writes in Ref. [28, p. 52]:
Thus an analyst or designer cannot rely on the person who
reads their diagrams and textual models having the same
interpretation of what an aggregate means as themselves.
In Section 2 of this paper, we review the evolution of
* Corresponding author. Tel.: 33-5-5992-3000; fax: 33-5-5980-8380.
E-mail addresses: Franck.Barbier@univ-pau.fr (F. Barbier),
brian@it.uts.edu.au (B. Henderson-Sellers).
0950-5849/01/$ - see front matter 2001 Elsevier Science B.V. All rights reserved.
PII: S0950-584 9(00)00133-6
20
Egg
Yolk
White
Eggshell
21
22
: object lifecycle
cp1
cp4
: WP linkage
cp2
cti : container i
cpj : component j
cp3
23
ct2
Fig. 2. Lanos fourth type of aggregation. Note that the origin of arrows
representing aggregation links does not describe the moment where the link
is created but only how wholes refer to parts.
in various ways. They specifically endorse lifetime dependency as the best choice: We choose aggregation to mean
life-time dependency; in particular, that the life-times of the
parts are contained within the life-time of the whole. The
parts are permanently attached to the whole, and cannot be
removed from it without being destroyed. Conversely,
destroying the whole destroys the parts. [11] (our
underlining). Cook and Daniels approach is appealing but
they are not clear in first saying, it might happen that:
when the aggregate is destroyed the parts may become
components of another. Indeed, this last textual extract
contradicts the sentence we previously underlined. Next,
they draw [11] a WP relationship whose cardinality near
the Whole role is 0..n. So, destroying the whole destroys
the part (the chosen meaning) but a part may have several
wholes (cardinality 0..n). Such an inconsistent situation
leads us to stress that lifetime dependency is a dangerous
property due to its incompatibility with sharing. In fact, it
would be a great pity to limit aggregation to lifetime dependency, even if physical objects behave as objects having the
same lifecycle (e.g. cup-handle, leg-femur).
Bourdeau and Chengs paper [9] is a formal proposition
using algebraic specifications. Despite the quality of the
proposed approach, no interesting semantics is proposed:
A semantics for aggregation must take into account that
the endpoints of the aggregation association are treated
somewhat differently than those of general binary associations However, the endpoints of the aggregation association cannot be interpreted, directly, as constraints on the
association. Instead, endpoints are interpreted as constraints
on the part name given as a label. [9, p. 811]. Informally,
Bourdeau and Chengs semantics relies on the following
assumption: navigation through aggregations is different
from navigation through associations. Navigation paths
are in particular defined from wholes to parts with the
help of total functions: p: Whole ! Part or p: Whole !
Part-SET (Part-SET is the power-set of the set Part). PartSET is used when an instance of Whole is connected with
more than one instance of Part. Unfortunately, most of the
usual criteria for describing the WP relationship are completely omitted in Bourdeau and Chengs discussion.
24
Generalizable Element
Association
1
connection
2..*
{ordered}
AssociationEnd
isNavigable : Boolean
isOrdered : Boolean
aggregation : AggregationKind
multiplicity : Multiplicity
changeable : ChangeableKind
targetScope : ScopeKind
AggregationKind = {none,aggregate,composite}
ChangeableKind = {none,frozen,addOnly}
ScopeKind = {instance,classifier}
Cell
Toothbrush
25
Bristle
{xor}
Tumour
Wig
none for changeable. Next, OCL may help the verification of compatible values between changeable and
multiplicity, for both association ends of a Composition. An extreme, but surely simple, solution is to definitively regard Composition as a fixed (frozen, no links
may be added after the creation of the source object.
[32, Semantics, p. 18]) structure with the cardinality
near the composite role being 1..1. In this case,
changeable becomes redundant because its value is
always frozen for each end. As with multiplicity,
it becomes useless for the association end embodying
the composite role.
Thus, Composition with the changeable attribute set to
frozen seems close to Lanos first type of aggregation
(bound, not shareable and not replaceable). Moreover, Composition with the changeable attribute set to
addOnly seems close to Lanos third type of aggregation
(bound, not shareable and replaceable). The difference is that, what Booch et al. say in Ref. [8]: Parts with
non-fixed multiplicity may be created after the composite
itself, but once created they live and die with it. is somehow in conformance with Lanos third type. As noted in
Ref. [21], this is not truly coincident lifetime because the
birth of wholes and parts does not coincide, even it is true
for the death.
Behind all of these observations appears the main drawback of the UML metamodel fragment in Fig. 3: Composition has not been viewed as a subclass of Association and
is not associated with the notions of emergent and resultant
properties. Even if the two new OCL expressions introduced
above improve the situation, to impose coincident lifetime
nevertheless remains difficult. Destroying the whole
destroys the parts is safe only if the Whole type properly
encapsulates the Part type. In Fig. 4(a), this does not seem to
be apply because an organ and a tumour may share a cell. Of
course, destroying the tumour leads to destroy the ill cells,
but the organ remains with the healthy cells. Paradoxically,
destroying the organ leads to destroy all the cells and then
justify our use of Composition! So, what is the best model?
The UML metamodel is incomplete in the sense it includes
no information in order to answer such a question. Civello in
Ref. [10]] usefully raises the problem in saying that A
shared part object cannot be encapsulated, as it must be
visible to more than one composite. In Fig. 4(b), the
model is more satisfactory since an exclusiveness constraint
is used (i.e. {xor}). In taking care of Civellos recommendation, it appears that encapsulation for the WP relationship
has to be formally defined (this definition will necessarily
exclude the possibility of sharing, especially in subtle cases
26
instance of
Whole-Part
Whole
Part
instance of
Metalmodel level
instance of
Model level
Instance level
as in Fig. 4) so that one can next, and only next, deal with the
idea of coincident lifetime.
Role(T)
cardinal : Integer
role : set of T
Invariants:
cardinal = #role
whites
0..1
blacks
0..1
Black
White
Structural-Relationship(Black,White)
add(Black,White): Role(Black) x Role(White)
cardinality(Black): Integer
cardinality(White): Integer
min-Black, max-Black, min-White, max-White: Integer
remove(Black,White): Role(Black) x Role(White)
Invariants:
2
(Black,White) M (Black White) Structural-Relationship(Black,White) Structural-Relationship(White,Black) =
(b,w) Black x White (b blacks(w).role w whites(b).role) blacks(w) nil whites(b) nil
b: Black cardinality(b) = whites(b).cardinal
b: Black min-White cardinality(b) max-White
w: White cardinality(w) = blacks(w).cardinal
w: White min-Black cardinality(w) max-Black
const min-Black ; min-Black 0
const max-Black ; max-Black > 0 max-Black min-Black
const min-White ; min-White 0
const max-White ; max-White > 0 max-White min-White
Pre-conditions and post-conditions:
add: Section 3.2.4 of this paper
b: Black cardinality(b) [whites(b) nil] / []
w: White cardinality(w) [blacks(w) nil] / []
remove: Section 3.2.3 of this paper
Creation:*
(i,j,k,l: Integer) [] / [i = min-Black j = max-Black l = min-White k = max-White]
Whole-Part(Whole,Part)
Invariants:
Whole Black
Part White
min-Whole min-Black ; max-Whole max-Black
min-Part min-White ; max-Part max-White
Fig. 6. Core of cOlOr. The two referential metarelationships from Structural-Relationship to Role support an access key (or qualifier), whose type is Black for
the first and White for the second.
instance of
27
b1
b2
b3
a1
Role(B)
whites
0..1
A
A
Structural-Relationship(A,B)
instance of
a1
b1
b2
b3
Fig. 7. At the metamodel level, T, Black and White have been replaced by effective types (Role(A) is not shown) due to the existence in an object model M of a
structural relationship between A and B.
remind the reader that UML offers a metaclass called Association which is close to the concept of structural relationship in cOlOr. Moreover, cOlOrs Black and White types
are regarded as two instances of Classifier. The Classifier metaclass is linked to AssociationEnd in the UML
metamodel thanks to an association (role type with
cardinality strictly equal to 1 near Classifier) [32, Semantics, p. 17]. In OML, the metatype Referential Relationship is linked to one and only one Client, as well as to
one and only one Server.
In Fig. 6, we focus on a new metatype called Role(T)
which is itself parameterised by the type T. Thus, given
an instance b of Black, there potentially exists one rb
instance of Role(White) such that rb embodies the set of
elements, instances of White, linked to b. In other words,
we have Structural-Relationship(Black,White)[b] rb in
which the square brackets act as an access operator and b
acts as the key. Intuitively, Role(T) describes the mapping
from Black to White when T is equal to Black, and viceversa. Fig. 7 gives an overview of the above principle. In
Fig. 6, two metarelationships from Structural-Relationship
(Black,White) to Role(T) indicate navigability. In Fig. 7,
given the type Structural-Relationship(A,B) from which
an instance is created to represent a structural relationship
between two types A and B in an object model M (Venn
diagram interpretation, bottom right), Role(B) is instantiated for each existing instance of A. An instance of
Role(B) is depicted here (Venn diagram interpretation, top
right) for an instance of A (a1) linked to three instances of B
(b1, b2 and b3).
28
Role(T)
whites
0..1
blacks
Compound(T)
wholes
0..1
0..1
Component(T)
parts
0..1
[redefines]
[redefines]
Black
White
Structural-Relationship(Black,White)
Whole-Part(Whole,Part)
Whole
Part
Finally, the fourth and last part of a box is named Creation and corresponds to the creation protocol. This part is
annotated with in Fig. 6 because we refer to it in
Section 4.2.5.
In Fig. 6, we have fully specified the functions supported
by Role(T). For Structural-Relationship(Black,White), we
argue about its detailed specification in Section 4.2. As
subtypes, Compound(T), Component(T) and Whole-Part
(Whole,Part) conform to these functions but define their
own constraints. There are some functions to compute the
current cardinality as well as its maximum and its minimum.
Moreover, we have made the assumption that, by definition,
a structural relationship is an evolving structure. In other
words, instances of Black and White can be freely
connected to each other, so long as the maximum and minimum cardinalities are respected. So, the Structural-Relationship metatype is flexible enough to cover what is
generally known as a general-purpose association in an
object model.
4.2. A characterisation of the WP relationship
The characterisation discussed here enhances that in Ref.
[20]. The chosen primary properties remain the same while
the secondary properties are formalised in a different way to
build well-formed and specialised types of aggregation.
4.2.1. Encapsulation
Encapsulation is a secondary property in Ref. [20]. It is
used here as a partition in order to define four categories of
coupling between the Whole type and the Part type. For an
object (a part), it can, in particular, be said to be encapsulated by another one (a whole) if the whole is the only object
in the total system at any moment which handles a reference
Given (Whole,Part) M M and WP: WholePart (Whole,Part), X MX X Whole ! StructuralRelationship (X,Part) , Structural-Relationship
(X,Part) {WP}
In other words, at the instance level, any linkage that has
Whole
WP
Part
Whole
Part
Whole
SR
SR
(a)
WP
(b)
29
WP
X
(c)
WP
Part
SR
X
30
Car engine
Car
WP1
WP2
SR
Front axle
WP3
Part of front
axle
Fig. 11. Mixing of some encapsulation characterisations for the WP
relationship.
application of type-transitivity violates type-antisymmetry. Finally, note that for the case (WE-c), X Whole
and X Part are permitted.
As shown in the model in Fig. 11, WP1 is an instance of a
subtype of the Whole-Part metatype that owns the property
(WE-c). WP2 is an instance of a subtype of Whole-Part that
owns the properties (WE-a) or (WE-c). Finally, WP3 is an
instance of a subtype of Whole-Part that owns the property
of strict encapsulation. What does not appear in Fig. 11 is a
dedicated notation for each of these subtypes.
Encapsulation, as described above, is a first step in guiding how models have preferably to be built. However,
encapsulation has deeper impacts at the instance level that
requires further refinement. In Fig. 12, we first add four new
metatypes (we write inside the boxes just what is new
compared to what is already specified in Fig. 6). They correspond to our four definitions of encapsulation and are used
next, as for dealing with instance-encapsulation.
4.2.2. Sharing and non-sharing
There is often a general assumption for the notion of
sharing in the literature. As it happens, some approaches
(in UML or in Ref. [15] for example) consider sharing in an
object model M, for a given WP relationship. In Ref. [26],
they extend such an assumption in talking about local/
global sharing as well as local/global exclusiveness.
Structural-Relationship(Black,White)
Whole-Part-WE-c(Whole,Part)
Whole-Part(Whole,Part)
Whole-Part-WE-b(Whole,Part)
Whole-Part-WE-a(Whole,Part)
Whole-Part-SE(Whole,Part)
Invariants:
2
(WP1,WP2) Whole-Part-SE(Whole,Part) , X M
X Whole -> Structural-Relationship(X,Part) = , Structural-Relationship(X,Part) = {WP1 = WP2}
Book
Picture
Article
Fig. 13. An extended view of the sharing principle of UMLs Aggregation
(cardinalities are not expressed).
31
added, if desired, to the specification of not only the WholePart-SE metatype (Fig. 12), but also the Whole-Part-WE-a
(we called that part-encapsulation based on WE-a) and
Whole-Part-WE-c (we called that part-encapsulation
based on WE-c) metatypes in Fig. 12. Finally, adding it
to Whole-Part-WE-b is possible but is not safe at all
because, by definition, instances of Part may be shared by
instances of two different types (Fig. 10(b)).
4.2.3. Separability and inseparability
As was the case with sharing, separability is, within
cOlOr, the default status of the Structural-Relationship
metatype. As a result, we may want to specify inseparability
and consider that such a property has to be given to a possible subtype of the Whole-Part metatype. Within cOlOr, the
remove operation of the Structural-Relationship metatype
is, in particular, used so that linkages between instances of
the two types participating in a given structural relationship
disappear.
Civello in Ref. [10, p. 385] emphasises Whole-Part
Inseparability as well as Part-Whole Inseparability.
However, he blends separabilityinseparability concerns
with lifetime dependency concerns. As it happens, with
Whole-Part Inseparability, an inseparable whole is such
that The part object cannot be deleted without causing the
deletion of the whole. Moreover, he considers that the lifetime of the whole is included within that of its part. Instead,
we give here a less restrictive definition and defer the analysis of lifetime dependency concerns to Section 4.2.5. As a
result, keeping Whole-Part Inseparability and PartWhole Inseparability is not justified within cOlOr.
Principle of separability for the structural-relationship
metatype
Invariants:
(b,w) Black WhiteX (b blacks(w).role , w
whites(b)role) ) blacks(w) nil whites(b) nil
This invariant means that the existence of a linkage
between b and w is materialised by an access for b,
respectively for w, to its linked whites, respectively
its linked blacks. Consequently, the multiplicity
constraint 0..1 of both metarelationships from
Structural-Relationship(Black,White) to Role(T) is
necessarily equal to 1 (i.e. if a linkage between b
and w exists.
Pre-conditions and post-conditions: (see for the
general form and note that in the rest of the part the use of
apostrophe means new value)
(b,w) Black WhiteX remove(b,w) [b blacks
(w).role]/[blacks(w).role blacks(w).role {b}
whites(b).role whites(b).role {w}]
In Fig. 7 for instance, whites(a1) is an instance of
Role(B), whites(a1).role {b1,b2,b3} and, as a result,
whites(a1).cardinal cardinality(a1) 3. After removing (a1,b1) for example, whites(a1).cardinal 2 and
blacks(b1).role blacks(b1).role (i.e. ) {a1}.
32
Whole
1..max-Whole
WP
Part
0..max-Part
Whole
0..max-Whole
WP
Part
1..max-Part
Whole
33
Part
WP
1..max-Whole
1..max-Part
(a)
(b)
(c)
34
specifications which could be cumbersome at implementation time, i.e. requiring a specific technique for the
creation of objects. As a result, in regard to the creation
process of the WP relationship, the following pre-condition is required: p PartX wholes(p) nil. This
means that no instance of Part existed at any moment
before linkage creation. To complete the specification
we write:
Creation: (this signature complements the general form
indicated by in Fig. 6)
( ) [p PartX wholes(p) nil]/( )
Coincident birth of Part and Whole instances with WP
linkages
We already have:
min-Whole 0
(w,p) Whole PartX add(w,p) [false]/[ ]
And we symmetrically add (mandatory participation
for Whole instances):
min-Part 0
Finally the creation protocol is modified as follows:
Creation: (this signature complements the general
form indicated by in Fig. 6)
( ) [p PartX wholes(p) nil w
Wholeparts(w) nil]/[ ]
Coincident death of Part instances with WP linkages
(necessary but non-sufficient)
min-Whole 0
If Part instances have optional participation, they
can exist before Whole instances to which they
will be connected (see above), as well as being
able to outlive the Whole instances to which they
were connected. So min-Whole 0 is once again
necessary.
part-encapsulation part-encapsulation based on
WE-a
Part-encapsulation is a safe mode because it supposes
non-sharing as well as the absence of references to
parts, except that of their single whole.
(w,p) Whole PartX remove(w,p)[false]/[ ]
Moreover, inseparability is obviously necessary.
Coincident death of Part and Whole instances with WP
linkages (necessary but non-sufficient)
We already have:
min-Whole 0
part-encapsulation part-encapsulation based on
WE-a
(w,p) Whole PartX remove(w,p) [false]/[ ]
And we symmetrically add (mandatory participation
for Whole instances):
min-Part 0
Coincident lifetime (necessary but non-sufficient)
min-Whole 0
(w,p) Whole PartX add(w,p)[false]/[ ]
min-Part 0
35
};
class Egg feature Eiffel
eggshell: expanded Eggshell;
white: White;
yolk: Yolk;
end
Such a dependency between the Egg and the Eggshell
classes views objects as values. In contrast, in most
object-oriented programming languages (Java and
Smalltalk in particular), the common way to handle
objects is by reference. In the previous code, an
instance of Egg manages an instance of Eggshell by
value. This last instance is invisible from outside
(private: in C and absence of export in Eiffel).
However, it is not mandatory to restrict the interface of
the Egg class so that the eggshell attribute is inaccessible from outside.
The code above seems to be appropriate to represent
ownership. Indeed, each time an instance of Egg is created,
an instance of Eggshell is automatically created. Furthermore, the code above is such that Civellos observation
becomes true: deletion of the whole object implies
deletion of the part object. The difference is that this
code prevents separability despite Civellos acceptance
of it. Finally, it is important to notice that any instance
embodied by the eggshell field can only react to
stimuli (service calls) from the instance of Egg owning
this field. We may change that in allowing this attribute
to become visible-but this raises other problems. To
sum up, we believe that:
Defining ownership at the analysis level is not a good
idea, because this requires taking into account relations
between wholes and parts, in taking care of implementation details. These relations are rarely programming
language-free specifically when they refer to deletion
mechanisms. In contrast, we might say that it is possible
to represent ownership independently of programming
languages provided that we do not use such dynamical
mechanisms.
Ownership is difficult to characterise at the designimplementation level in the case of one-to-many relationships. Indeed, an aggregation from Egg to
Eggshell is a simplistic example compared to a
Whole object that owns an arbitrary number of Part
objects. This implies the use of collections (i.e.
containers) and then the need for extra implementation. In addition, remember that neither Java nor
Smalltalk support object management by value. This
dramatically limits the spectrum of ownership. Our
regret (which is also a criticism!) is that some
well-known contributions have reversed the problem
in giving a definition of the WP relationship, said to
be free of programming languages, but actually
36
Structural Relationship(Black,White)
Whole-Part(Whole,Part)
UML-Composition(Whole,Part)
coincident lifetime: Section 3.2.5 of this paper
Whole-Part-SE(Whole,Part)
Fig. 15. Specification of UMLs Composition in cOlOr.
Structural Relationship(Black,White)
Whole-Part(Whole,Part)
Whole-Part-WE-c(Whole,Part)
OML-Aggregation(Whole,Part)
Invariants:
min-Part > 0
Optical path
0..1
1..max-Part
Optical-path-layerlink-connection
Fig. 17. A domain-dependent WP relationship.
37
38
Acknowledgements
This is Contribution number 99/5 of the Centre for Object
Technology Applications and Research.
7. Conclusions
References
In object modelling, a plethora of papers on aggregation
gives a very non-uniform view of this kind of structural
relationship. This phenomenon was illustrated in Section
3. Theoretically, it is possible to attribute a set of axiomatic
properties to the WP relationship but, as discussed in
Section 2, it is then easy to find an example that clashes
[1] F. Barbier, Systematic Construction of UML Associations and Aggregations Using cOlOr Framework, Proceedings of Automating the
Object-Oriented Software Development in ECOOP98 Workshop
Reader, Lecture Notes in Computer Science, vol. 1543, Springer,
New York, 1998 (pp. 480482).
[2] F. Barbier, J. Cherel, S. Rideau, Submarine Telecommunications
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[10]
[11]
[12]
[13]
[14]
[15]
[16]
[17]
[18]
[19]
[20]
[21]
[22]
[23]
[24]
[25]
[26]
[27]
[28]
[29]
[30]
[31]
[32]
[33]
[34]
[35]
[36]
[37]
[38]
[39]
[40]
39