Knowledge7

The Linux and Mobile Solution Provider

  • About
  • Training
  • Services
  • Clients
  • In the news
  • Blog
  • Contact Us
You are here: Home / Topic / Inheritance and Object-Orientation

Inheritance and Object-Orientation

This topic is part of our Mastering Computer Programming training

Object-Oriented Programming, as opposed with Object-Based Programming, is when the programmers uses Inheritance between classes to implement the application. In many cases, inheritance makes the code easier to extend and maintain. Furthermore, in the real world, inheritance exists (in the sense that a Dog and a Cat are both Animals and, consequently, they share some behaviours) and, by properly using inheritance, the program becomes much clearer. Chapter 17 of the book explains how to use inheritance.

Work to do

We are now going to enhance our race simulation program by using inheritance to make it fully object-oriented.

Up to now, a race was won by the driver who has the best ability and, if there are many such drivers, the one driving the fastest car. This is artificial in the sense that it’s always the same drivers (those with maximum ability) who win. In real-life, the winner is not always the best driver:

  • Sometimes, because of luck, a lesser driver wins. This can be modeled, for example, by simulating an actual race over a distance and assuming that a car travels along a distance which is proportional to the performance of the car but biased with an element of randomness.
  • Some races might be handicap-based where those drivers with more ability start behind others. Naturally, here also it is good to have an element of randomness to make things more interesting.
This topic is part of our Mastering Computer Programming training

Our forthcoming training courses

  • No training courses are scheduled.

Leave a Reply

Your email address will not be published. Required fields are marked *

Looking for something?

Want to know more?

Get our newsletter

Discover the latest news, tips and tricks on Linux, the Web and Mobile technologies every week for FREE

This work is licensed by Knowledge7 under an Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.