OOP Inheritance

In this chapter, we will discuss the second pillar of object-oriented programming, inheritance. Image: OOP Pillars – Inheritance

Updated

DRY Code

  1. DRY Code (Novice): Classes that repeat the same variables and methods break the DRY principle, and merging them into one class is not the answer.

Introduction to Inheritance

  1. Introduction to Inheritance: an overview (Apprentice): Inheritance is an is-a relationship, where a child class such as Archer gets all the variables and methods of its parent class, Character, and adds its own.
  2. Generalization vs Specialization (Apprentice): Generalization moves what classes share into one parent class, and specialization keeps what makes each child class different.
  3. Inheritance in Java (Apprentice): In Java, a child class inherits from a parent class with the extends keyword and then adds its own variables and methods.
  4. Inheritance and Constructors (Journeyman): When a parent class has only constructors with parameters, the child class's constructor must call super(...) with those values as its first line.
  5. Overriding Methods (Journeyman): Override an inherited method with @Override and call super to keep the parent's logic while adding your own.