🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators base
This page was created by Hans.karlsen on 2018-07-21. Last edited by Wikiadmin on 2026-07-29.

Use the base operator in an overriding method to call the implementation of that method in its superclass.

Call a superclass implementation

When a subclass overrides a method such as OnCreate(), the overriding method replaces the inherited implementation for that subclass. Use self.base.MethodName() when the subclass must also run the superclass implementation.

For example, an overriding OnCreate() method can perform work before and after the inherited OnCreate() method:

self.OtherCallsBeforeCodeInOverridenClassIsDone();
self.base.OnCreate();
self.OtherCallsAfterCodeInOverridenClassIsDone()

In this example, execution occurs in this order:

  1. OtherCallsBeforeCodeInOverridenClassIsDone() runs on the subclass instance.
  2. base.OnCreate() runs the OnCreate() implementation inherited from the superclass.
  3. OtherCallsAfterCodeInOverridenClassIsDone() runs on the subclass instance.

Choose where to call base

The position of the base call determines when the superclass code runs.

Goal Pattern Result
Run superclass initialization before subclass initialization self.base.OnCreate(); followed by subclass calls The inherited OnCreate() runs first.
Run subclass preparation before superclass initialization Subclass calls followed by self.base.OnCreate(); The subclass preparation runs first.
Run subclass code on both sides of superclass initialization Subclass calls, self.base.OnCreate();, then more subclass calls The superclass implementation runs between the two subclass operations.

Requirements and limitations

  • Use base from the overriding implementation in the subclass.
  • Call the inherited method by its method name, for example self.base.OnCreate().
  • If you do not include a base call, the superclass implementation is not called by the overriding method.
  • Call base only when the superclass method's behavior is required. Calling it before or after subclass code can change initialization order.

Example: preserve inherited creation behavior

Assume a superclass defines OnCreate(), and a subclass overrides it to add its own setup. To preserve the inherited creation behavior while adding subclass work, call the superclass method explicitly:

self.SetupSubclassState();
self.base.OnCreate();
self.SetupAfterInheritedCreate()

This pattern makes the intended order visible: subclass setup, inherited creation logic, then follow-up subclass setup.

See also