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.
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:
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.