Previous | Table of Contents | Next |
An extension is used to indicate that the properties of a metaclass are extended through a stereotype, and gives the ability
to flexibly add (and later remove) stereotypes to classes.
Description
Extension is a kind of Association. One end of the Extension is an ordinary Property and the other end is an ExtensionEnd.
The former ties the Extension to a Class, while the latter ties the Extension to a Stereotype that extends the Class.
Generalizations
•
“Association? on page 109
Attributes
• package : Package [0..1] The containing package.
• / isRequired: Boolean Indicates whether an instance of the extending stereotype must be created when an instance of the extended class is created. The attribute value is derived from the multiplicity of Extension::ownedEnd; a multiplicity of 1 means that isRequired is true, but otherwise it is false. Since the default multiplicity of an ExtensionEnd is 0..1, the default value of isRequired is false.
Associations
• ownedEnd: ExtensionEnd [1] References the end of the extension that is typed by a Stereotype. Redefines Association::ownedEnd.
• / metaclass: Class [1] References the Class that is extended through an Extension. The property is derived from the type
of the memberEnd that is not the ownedEnd.
Constraints
[1] The non-owned end of an Extension is typed by a Class.
metaclassEnd()->notEmpty() and metaclass()->oclIsKindOf(Class)
[2] An Extension is binary, i.e., it has only two memberEnds.
self.memberEnd->size() = 2
Additional Operations
[1] The query metaclassEnd() returns the Property that is typed by a metaclass (as opposed to a stereotype)
Extension::metaclassEnd(): Property;metaclassEnd = memberEnd->reject(ownedEnd)
[2] The query metaclass() returns the metaclass that is being extended (as opposed to the extending stereotype).
Extension::metaclass(): Class;metaclass = metaclassEnd().type
[3] The query isRequired() is true if the owned end has a multiplicity with the lower bound of 1.
Extension::isRequired(): Boolean;isRequired = (ownedEnd->lowerBound() = 1)
Semantics
A required extension means that an instance of a stereotype must always be linked to an instance of the extended metaclass.
The instance of the stereotype is typically deleted only when either the instance of the extended metaclass is deleted, or
when the profile defining the stereotype is removed from the applied profiles of the package. The model is not well formed
if an instance of the stereotype is not present when isRequired is true.
A non-required extension means that an instance of a stereotype can be linked to an instance of an extended metaclass at will,
and also later deleted at will; however, there is no requirement that each instance of a metaclass be extended. An instance
of a stereotype is further deleted when either the instance of the extended metaclass is deleted, or when the profile defining
the stereotype is removed from the applied profiles of the package.
The equivalence to a MOF construction is shown in Figure 13.4. This figure illustrates the case shown in Figure 13.6, where
the “Home? stereotype extends the “Interface? metaclass. The MOF construct equivalent to an extension is an aggregation from
the extended metaclass to the extension stereotype, navigable from the extension stereotype to the extended metaclass. When
the extension is required, then the cardinality on the extension stereotype is “1.? The role names are provided using the
following rule: The name of the role of the extended metaclass is:
‘base$’ extendedMetaclassName
The name of the role of the extension stereotype is:
‘extension$’ stereotypeName
Constraints are frequently added to stereotypes. The role names will be used for expressing OCL navigations. For example,
the following OCL expression states that a Home interface shall not have attributes:
self.baseInterface.ownedAttributes->size() = 0
base$Interface extension$Home
Home
1 0..1
Figure 13.4 MOF model equivalent to extending “interface? by the “Home? stereotype
Notation
The notation for an Extension is an arrow pointing from a Stereotype to the extended Class, where the arrowhead is shown as
a filled triangle. An Extension may have the same adornments as an ordinary association, but navigability arrows are never
shown. If isRequired is true, the property {required} is shown near the ExtensionEnd.
Figure 13.5 - The notation for an Extension Presentation Option
It is possible to use the multiplicities 0..1 or 1 on the ExtensionEnd as an alternative to the property {required}. Due to
how isRequired is derived, the multiplicity 0..1 corresponds to isRequired being false.
Style Guidelines
Adornments of an Extension are typically elided.
Examples
In
Figure 13.6
, a simple example of using an extension is shown, where the stereotype Home extends the metaclass Interface.
Figure 13.6 - An example of using an Extension
An instance of the stereotype Home can be added to and deleted from an instance of the class Interface at will, which provides
for a flexible approach of dynamically adding (and removing) information specific to a profile to a model.
In
Figure 13.7
, an instance of the stereotype Bean always needs to be linked to an instance of class Component since the Extension is defined
to be required. (Since the stereotype Bean is abstract, this means that an instance of one of its concrete subclasses always
has to be linked to an instance of class Component.) The model is not well formed unless such a stereotype is applied. This
provides for a way to express extensions that should always be present for all instances of the base metaclass depending on
which profiles are applied. .
Figure 13.7 - An example of a required Extension
Changes from UML 1.4
Extension did not exist as a metaclass in UML 1.x.
Occurrences of Stereotype::baseClass of UML 1.4 is mapped to an instance of Extension, where the ownedEnd is typed by Stereotype
and the other end is typed by the metaclass that is indicated by the baseClass.