Author: Steven Clauwaert

Contents

The project concerns a systematic description of associations and the different forms of associations in UML.

Furthermore a short description is given of the constructions in OCL.

Associations

Associations are the means for establishing relationships among classes.

They describe a group of links with common structure and semantics. It describes a set of potential links between the classes.

An association defines a semantic relationship between classes. The instances of an association are a set of tuples relating instances of the class. Each tuple value may appear at most once.

Associations are often modeled bi-directional but they do not necessary have to be that. The direction that has a name is usually called the forward direction and the other the inverse direction. Hence a Person “works for” a Company, or a Company “employs” a Person. In practice an association can be implemented by a pointer.

A pair of matched pointers can be used to create bi-directional associations, for example a Person might contain an attribute that points to the Company and a Company might contain an attribute to connect to a set of Employee.

Associations in UML

i Reference: Object oriented design books.

ii Reference: umlcore.ps, Tom Østerby, modified for report purpose.

The UML notation for an association is a line between classes normally accompanied by a name to indicate the directions.

i Object oriented design books :

  1. Object Oriented Systems Analysis and design using UML – Bennet, McRobb, Farmer – 1999 – ISBN 0-07-709497-2

  2. Object Oriented Analysis and design– Martin and Odell – 1992 – ISBN 0-13-630245-9

  3. Object Oriented Modeling and design– Rumbaugh, Blaha, Premerlani – 1991- ISBN 0-13-629841-9

ii Source : Umlcore.ps : Tom Østerby – 16 august 1999 – OMG – UML Core Package

UmlAssociations

An instance of an Association is a Link, which is a tuple of Instances drawn from the corresponding Classes. A link shows the relationship between class instances.

Besides having a name an association has a set of properties also located at the association-end (e.g. which Class the instance must conform to, their multiplicity, and if they may be reached from another Class instance via this connection). These are discussed in the following part.

An association-end has the following Attributes:

Name

The role name of the association end. It provides a name for traversing from a source instance across the association to the target instance or set of target instances. It represents a pseudo-attribute of the source Class (i.e., it may be used in the same way as an Attribute) and must be unique with respect to attributes and other pseudo-attributes of the source Class

Multiplicity

Specifies the number of target instances that may be associated with a single source instance across the given Association.

UmlMultiplicity

Figure 1 : A Company employs 0 or more Persons, and a Person works for one Company

Visibility

Specifies the visibility of the association end from the viewpoint of the Class on the other end.

UmlVisibility

Figure 2 : Visibility shown in the class

  • public’ (‘+’) : other classes may navigate the association and use the role name in expression, similar to the use of a public attribute.
  • ‘protected ‘ (‘#’) : descendants of the source class may navigate the association and use the role name in expressions, similar to the use of a protected attribute.

  • ‘private’ (‘-‘) : only the source class may navigate the association and use the role name in expressions, similar to the use of a private attribute.

Changeability

Specifies whether an instance of the Association may be modified from the source end.

  • ‘changeable’ : no restriction on modifications.

  • ‘frozen’ : no links may be added after the creation of the source object.

  • ‘addOnly ‘: links may be added at any time from the source object, but once created a link may not be removed from the source end.

Ordering

Specifies whether the set of links from the source instance to the target instance is ordered. The ordering must be determined and maintained by Operations that add links. It represents additional information not inherent in the objects or links themselves.

  • ‘unordered ‘: links form a set with no inherent ordering.

  • ‘ordered ‘: links can be scanned in order.

IsNavigable

Specifies whether traversal from a source instance to its associated target instance is possible or not ‘true’ or ‘false’. Specification of each direction across the Association is independent. Traversal means that the source class can navigate the association and the target role name can be used in the navigation expression.

TargetScope

Specifies whether the target value is an instance or a class.

  • ‘instance’ : an instance value is part of each link. This is default.

  • ‘classifier ‘ : a class itself is part of each link. Normally this would be fixed at modeling time and need not be stored separately at run time.

Aggregation

UmlAggregate
Figure 3 : Aggregate

Aggregation is a mechanism for forming an object whole using other object as its parts. Only one end can be an aggregation. A part may belong to many aggregates. Parts may be created and inserted after the aggregate itself and may be removed explicitly from the aggregate. An aggregate may have recursive parts.

 

If an aggregate is removed, its parts will still exist.

  • ‘none’ : the end is not an aggregate.

  • ‘aggregate’: the end is an aggregate, therefore, the other end is a part and must have the aggregation value of ‘none’. The part must be contained in other aggregates. The multiplicity at the composite end may be more than one. This is also called shared aggregation, which exists rarely and mostly in nonphysical concepts. This situation can occur when the element is owned by a container but referenced from in more than one other containers. Below an example of this is shown. UmlLibraryAggregate

  • composite’ : the end is a composite, therefore, the other end is a part and must have an aggregation value of ‘none’. The part is strongly owned by the composite and may not be part of any other composite. A part may belong to only one composite. A compUmlAggregateCompositionosite may have recursive parts. Parts may be created and inserted after the composite itself. and may be removed explicitly from the composite. Composite being removed causes its part to be removed. Composition is also called composite aggregation, which means that the multiplicity at the composite end may be at most one.

    In case of a composition the role name would most common be “has a”, so this is often omitted. +* This is shown with the filled diamond. An example is shown below:

UmlAggregateCompositionFingerHand

Aggregation can be shown when the lifetimes are bound, or there is an obvious whole-part functional relationship, or when operations or properties propagate to the parts, such as destruction, location, movement or recording.

The following figure shows that any instance of Point may be in either a Circle or in a Polygon, and not in both at the same time. Circles and Polygons on the other hand may share the Style. When the polygon is deleted or destroyed the associated points belonging to the Polygon should be deleted.

UmlCompareAggregateComposition

Associations in OCL

iReference: Object Constraint Language Specification, v 1.1

iiReference:Aggregation: Kinds

OCL is described as a navigation language for UML diagrams.

A path specifies an object or a set of objects being instances of the class.

It is possible to navigate from one class to another class using associations and association classes.

Starting from a specific object, we can navigate an association on the class diagram to refer to other objects and their properties. To do so, we navigate the association by using the opposite association-end:

object.rolename

The value of this expression is the set of objects on the other side of the rolename association. If the multiplicity of the association-end has a maximum of one (“0..1” or “1”), then the value of this expression is an object. In the example class diagram, when we start in the context of a Company (i.e. self is an instance of Company):

UmlOclCompanyPerson

Company

self.manager — is of type Person

self.employee — is of type Set(Person)

The evaluation of the first expression will result in an object of type Person, because the multiplicity of the association is one. The evaluation of the second expression will result in a Set of Persons. By default, navigation will result in a Set. When the association on the Class Diagram is adorned with {ordered}, the navigation results in a Sequence. Collections, like Sets, Bags and Sequences, are predefined types in OCL. They have a large number of predefined operations on them.

Using an arrow ‘->‘ followed by the name of the property accesses a property of the collection itself. The following example is in the context of a person:

Person

self.employer->size

This applies the size property on the Set self.employer, which results in the number of employers of the Person self.

Person

self.employer->isEmpty

This applies the isEmpty property on the Set self.employer. This evaluates to true if the set of employers is empty, and false otherwise

At most one AssociationEnd may be an aggregation or composition.

self.allConnections->select(aggregation <#none)->size <= 1

.

Navigation over Associations with Multiplicity

Because the multiplicity of the role manager is one, self.manager is an object of type Person. Such a single object can be used as a Set as well. It then behaves as if it is a Set containing the single object. The usage as a set is done through the arrow, followed by a property of Set. This is shown in the following example:

UmlCompanyPerson

Company

self.manager->size

‘self.manager’ is used as Set, because the arrow is used to access the ‘size’ property on Set. This expression result in 1

self.manager->foo

‘self.manager’ is used as Set, because the arrow is used to access the ‘foo’ property on Set. This expression is incorrect, since ‘foo’is not a defined property of Set..

self.manager.age

‘self.manager’ is used as Person, because the dot is used to access the ‘age’ property of Person.

In the case of an optional (0..1 multiplicity) association, this is especially useful to check whether there is an object or not when navigating the association.

Figure 10 : OCL multiplicity association navigation

Person

self.wife->notEmpty implies self.wife.sex = female

UmlOCLMultiplicity

Association rules

1. The AssociationEnds must have a unique name within the Association.

self.allConnections->forAll( r1, r2 | r1.name = r2.name implies r1 = r2)

2. At most one AssociationEnd may be an aggregation or composition.

self.allConnections->select(aggregation <#none)->size <= 1

3 If an Association has three or more AssociationEnds, then no AssociationEnd

may be an aggregation or composition.

self.allConnections->size >=3 implies

self.allConnections->forall(aggregation = #none)

4. The connected Classifiers of the AssociationEnds should be included in the

Namespace of the Association.

self.allConnections->forAll (r | self.namespace.allContents->includes (r.type)

Additional operations. The operation allConnections results in the set of all AssociationEnds of the Association.

allConnections : Set(AssociationEnd);

allConnections = self.connection

5. Discriminator names must be distinct from attribute names and opposite AssociationEnd names.

self.allDiscriminators->intersection (self.allAttributes.name->union

(self.allOppositeAssociationEnds.name))->isEmpty

Association Class

An association may be refined to have its own set of features (i.e., features that do not belong to any of the connected classifiers) but rather to the association itself. Such an association is called an association class. It will be both an association, connecting a set of classifiers, and a class, and as such have features and be included in other associations. The semantics of such an association is a combination of the semantics of an ordinary association and of a class.

The Association Class construct can be expressed in a few different ways in the metamodel (e.g., as a subclass of Class, as a subclass of Association, or as a subclass of Classifier). Since an Association Class is a construct being both an association (having a set of association-ends) and a class (declaring a set of features), the most accurate way of expressing it is as a subclass of both Association and Class. In this way, Association Class will have all the properties of the other two constructs. Moreover, if new kinds of associations containing features (e.g., AssociationDataType) are to be included in UML, these are easily added as subclasses of Association and the other Classifier.

References

Object oriented design books :

Object Oriented Systems Analysis and design using UML – Bennet, McRobb, Farmer – 1999 – ISBN 0-07-709497-2

Object Oriented Analysis and design– Martin and Odell – 1992 – ISBN 0-13-630245-9

 Object Oriented Modeling and design– Rumbaugh, Blaha, Premerlani – 1991- ISBN 0-13-629841-9

ii Source : Umlcore.ps : Tom Østerby – 16 august 1999 – OMG – UML Core Package

iii Source : Aggregat.txt : Tom Østerby – 21 february 2002 – Aggregation: Kinds

iv Source : OCLrefrence,ps : Object Constraint Language Specification, v 1.1 – September 1997 ad/97-08-08 Copyright © 1997 – IBM Corporation. -Rational Software Corporation.- Microsoft Corporation.- Hewlett-Packard Company.- Oracle Corporation.- Sterling Software.- MCI Systemhouse Corporation.- Unisys Corporation.- ICON Computing.

– IntelliCorp.- i-Logix.- ObjecTime Limited.- Platinum Technology Inc.- Ptech Inc.- Taskon A/S.- Reich Technologies.- Softeam.

The most recent updates on the Unified Modeling Language are available via the worldwide web: http://www.rational.com/uml.

A free OCL Parser and the most recent information on the Object Constraint Language are available via the worldwide web: http://www.software.ibm.com/ad/ocl.

Relevant OCL/UML links:

IBM: http://www.ibm.com/software/ad/standards/ocl.html

Rational: (OCL 1.1 browsable): http://www.rational.com/uml/resources/documentation/ocl

Klasse: http://www.klasse.nl/ocl

Rational: http://www.rational.com/uml

OMG: http://www.omg.org/uml

Download reference doc: UML 1.3 (includes OCL 1.3): http://www.rational.com/uml/resources/documentation/index.jtmpl

This website uses cookies to ensure you get the best experience on our website. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible and language settings. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close