LPTHW Exp43 : Why create class Scene(object)

I have understood most of the code, but i am unable to understand why all the scene classes (CentralCorridor,LaserWeaponArmory, TheBridge, etc) are created as subclass of class Scene.
Why to inherit and override rather than just create enter method for all of them?

It’s not strictly necessary in this simple case, but it’s a common pattern in object oriented programming. When you have a couple of things that are like different versions of a common concept, you make a base class that contains everything they have in common, and subclasses that contain individual stuff.

It helps to avoid repetition (DRY). Also, in other languages that have a stronger type system than Python you must do this because you can’t just throw arbitrary things together like Python does, but rather you must always declare the type/ class/base class of your variables.

In this case, by making Scene a base class you ensure that all subclasses have an enter method even if you haven’t implemented it yet.

1 Like

Now I understood why base class is required.
Thanks @florian.