A developer writes a class `Logger` with a method `log(self, message)`. They want to ensure that when `Logger` is subclassed, any override of `log` must call the parent's `log` method. Which technique best enforces this requirement in Python?
Python does not provide a built-in way to enforce that a subclass override calls the superclass method. This is by design, as Python relies on conventions and developer discipline. While design patterns like the template method can encourage it, they do not enforce it. The correct answer acknowledges this limitation.
Why this answer
Python's philosophy emphasizes flexibility and developer responsibility. There is no language-level construct that forces a subclass to call `super().log()`. Techniques like abstract methods ensure implementation but not invocation of the parent.
Metaclasses or descriptors could be used to add checks, but they are not built-in and are overly complex. The correct answer recognizes that enforcement is not a built-in feature.
Exam trap
The trap here is assuming that abstract methods or other decorators can enforce that a subclass calls the parent method, when they cannot.