0
Module or inherit?
In the jet, plane, car example, why use a module "flyable" over creating another class like "flying_vehicle" as superclass of plane and jet, that has the method fly. I know that in this example it probably doesnt matter, but in general, when do i use modules instead of a inheritance setup?
1 Answer
0
Though both have some common traits, they essentially serve different purposes.
In professional development, modules are used more than inheritance because modules are more flexible.
The example in your question, we could obviously use a super class named 'flying_vehicle' and inherit from that. but that't too much work.
Instead, we could just add the 'flyable' and 'drivable' module to implement a car that can both drive and fly.
This makes the codebase much smaller, cleaner and thus very easy to maintain.