Understanding inheritance
In this section, we'll learn about inheritance. Inheritance in object-oriented programming is a method for doing code reuse. This will shrink our application code size and make it more readable. Also, generally, shorter code tends to have fewer bugs. So, all these factors will improve our app quality once we get started building.
As stated, inheritance is primarily about allowing code reuse. Inheritance is also conceptually designed to be like real-life inheritance so that the logical flow of inheritance relationships can be intuitive and easier to understand. Let's look at an example of this now. Create a file called classInheritance.ts
and add the following code:
class Vehicle { constructor(private wheelCount: number) {} showNumberOfWheels() { console.log(`moved ${this.wheelCount} miles`); } } class Motorcycle extends Vehicle...