You can use self.base.OperationName() in an OCL/EAL operation on a subclass to run the implementation that the subclass overrides; this is for modelers who need inherited behavior to remain part of an overridden operation.
Call an overridden superclass operation
A class can inherit operations from a superclass. When a subclass provides its own implementation of an inherited operation, it overrides that operation. The subclass implementation is then the one that runs for objects of the subclass.
Use the EAL base operation when the overriding implementation must also run the superclass implementation:
self.base.OnCreate()
In this expression:
selfis the current object.baseidentifies the superclass implementation for the current override.OnCreate()is the operation being overridden and invoked on the superclass.
The call has the same purpose as calling a base-class implementation in C#.
Example: preserve common creation behavior
Assume that Person inherits from RootClass. Both classes implement OnCreate(), an operation that runs when an object is created.
| Class | Operation implementation | Purpose |
|---|---|---|
RootClass
|
OnCreate() adds RA to the output.
|
Defines behavior shared by all subclasses. |
Person
|
OnCreate() calls self.base.OnCreate(), then adds PA to the output.
|
Keeps the shared behavior and adds Person-specific behavior. |
Write the overriding operation in Person in this order:
self.base.OnCreate();
self.OtherCallsAfterCodeInOverridenClassIsDone()
Replace self.OtherCallsAfterCodeInOverridenClassIsDone() with the EAL that is specific to Person. In the example, that code adds PA.
When you create a Person, the superclass implementation runs first and adds RA; the Person implementation then runs and adds PA. The resulting output is RAPA.
Choose the execution order
Place self.base.OnCreate() where the inherited behavior must occur in relation to the subclass behavior.
| Placement in the overriding operation | Result | Example use |
|---|---|---|
| Before subclass-specific EAL | The superclass behavior runs first. | Initialize common state before the subclass adds its own state. |
| After subclass-specific EAL | The subclass behavior runs first. | Perform common follow-up work after the subclass behavior. |
For example, the following order performs work before and after the inherited implementation:
self.OtherCallsBeforeCodeInOverridenClassIsDone();
self.base.OnCreate();
self.OtherCallsAfterCodeInOverridenClassIsDone()
Important behavior
- Calling
self.base.OnCreate()invokes the superclass implementation from the overriding implementation. - If you do not make the
basecall, the superclass implementation is not included by this override. Use this deliberately when the subclass is meant to replace, rather than extend, inherited behavior. - Call the operation that you are overriding. For an override of
OnCreate(), callself.base.OnCreate(). - Keep shared behavior on the superclass and add only class-specific behavior in subclasses. This makes the inheritance hierarchy easier to maintain.
Related concepts
Use this feature for behavior defined in the model. If you need to run external C# logic from a Turnkey server-side model operation, use the extension approach described in Documentation:Calling your own c - sharp .net things from Turnkeyâserver side. For operations that users invoke from the model, see Documentation:Class actions.
