Rule Overriding
Transformation rules in MOFScript can override other
rules, either from imported transformations or within the same transformation.
This has two possible effects:
- Overriding
a rule with a new rule with a different context type (the metaclass it applies
to), will have the effect that different rules with the same name will be
called depending on the metatype. This will have a kind of polymorphic effect
with respect to the context type.
- Overriding
a rule from an imported transformation with a new one with the same signature.
This will merely ensure that calls to that rule will be to the overriding one.
Overriding
a rule from a super transformation in a sub transformation (inheritance
overriding). The sub transformation rule will be called instead of the super
one. The specializing rule may invoke the rule of the super transformation by
using the ‘super’ keyword.
uml.Package::uml2ecore () {
'
<ecore:EPackage
name="'self.name'">
'
self.ownedMember->forEach(member:uml.Element)
member.uml2ecore()
'
</ecore:EPackage>
'
}
uml.Class::uml2ecore () {
…
}