Skip to content

Profiles for enforcing base calls in virtual overrides: [[call_base]], [[pre_call_base]], [[post_call_base]] #12

@FadyDhaim

Description

@FadyDhaim

In many cases, we may need to override the functionality of a parent class with one that, albeit doing something on its own, still requires the base class’s version of the method to complete its job. This may chain up to the default virtual method. For that, we could use something like [[call_base]] or [[call_super]] on the virtual method, which would trigger a compile-time warning in the subclass implementation if the base implementation is not called.

we can further extend this idea with two variants concerned with statement order:

  • one that requires the base method to be called before the subclass logic,
  • and another that requires it to be executed afterward.
    These could be named [[pre_call_base]] and [[post_call_base]] respectively.

Edit:
this can be immensely useful for safety when implementing some design patterns specifically the Decorator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions