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?

31st May 2017, 9:44 AM
The Worldcreator
The Worldcreator - avatar
1 ответ
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.
1st Jul 2017, 11:03 AM
Salekin
Salekin - avatar