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.
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 multiplic- ity of Extension::ownedEnd; a multiplicity of 1 means that isRequired is true, but other- wise 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 Associa- tion::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
metaclassEnd()->notEmpty() and metaclass()->oclIsKindOf(Class)
Additional Operations
Extension::metaclassEnd(): Property;
metaclassEnd = memberEnd->reject(ownedEnd)
Extension::metaclass(): Class;
metaclass = metaclassEnd().type
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.
In order to be able to navigate to the extended metaclass when writing constraints, the end must have a name. If no name
is given, the default name is baseClass.
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.
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 111, a simple example of using an extension is shown, where the stereotype Home extends the metaclass
Interface.
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 112, 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. .
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.