Previous UML Classes Table of Contents UML Packages Next


18.3.2 Extension

Profiles


   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.

*Generalizations

   

   InfrastructureLibrary::Constructs::Association

   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

Issue 8596 - multiplicity of the referenced property deternines attribute value

• / 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 the Property referenced by 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

   Issue 8596 - change redefines to subsets 9188 - change subsets constraint to redefines constraint

   • 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).

   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

Issue 8256 -add last sentence about the case when stereotype has subclasses

   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. If the extending stereotype has subclasses, then at most one instance of the stereotype or one of its subclasses is required.

   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.

Issue 8596 -insert sentence clarifying relationship to CMOF concepts

   The equivalence to a MOF construction is shown in Figure 18.4. This figure illustrates the case shown in Figure 18.6, where the Home stereotype extends the Interface metaclass. In this figure, Interface is an instance of a CMOF::Class and Home is an instance of a CMOF::Stereotype . 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:

Issue 9186 -replace ‘$’ with underscore character

   ‘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.base_Interface.ownedAttributes->size() = 0

Issue 9186 -replace ‘$’ with underscore character


   Figure 18.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 18.5 - The notation for an Extension

   Presentation Options

   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 18.6 , a simple example of using an extension is shown, where the stereotype Home extends the metaclass Interface.


   Figure 18.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 18.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 a way to express extensions that should always be present for all instances of the base metaclass depending on which profiles are applied.


   Figure 18.7 - An example of a required Extension

   Changes from previous UML

   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.