Inheritance


Premium Content - Free Preview

In the last node, you saw how different car instances can be created from one Car Class without having to re-write any code. But what if you wanted to create another car that was similar but needed a modified template? For example, you might want to create some of the following:

  • 2 different racecars, like a Formula 1 Racecar and a Rocket Car.
  • Consumer cars, like the Toyota Camry and a the Ford Explorer.
  • Other vehicles, like Trucks and Motorcycles.

Each type of vehicle will overlap in many ways, but also have different types of state and actions. For example, a Motorcycle can do a wheelie, while a truck can attach another cart behind it. Since each instance of a Class follows the same template, these different vehicles cannot belong to the same class. Another approach is needed.


End of Free Content Preview. Please Sign in or Sign up to buy premium content.

Comments

Contact Us
Sign in or email us at [email protected]