donnemartin/system-design-primer

Supervisor Class Implementation

vladlen-codes opened this issue · 1 comments

The error in the Supervisor class implementation is a classic inheritance bug that would cause issues at runtime.

Problems this causes:

  • Method Resolution Order (MRO) issues: This incorrect super() call will disrupt the normal MRO that Python uses to resolve inheritance.
  • Runtime error: It will raise a TypeError with a message like: "super(type, obj): obj must be an instance or subtype of type" because when inside the Supervisor class, self is not an instance of Operator.
  • Initialization issues: If it somehow didn't raise an error, it would initialize the object incorrectly, potentially accessing the wrong parent class methods.

Use super() with the current class:

class Supervisor(Operator):
def init(self, name, department):
super().init(name)
self.department = department