Inheritance

In OOP, classes can inherit variables and Functions from other classes. When we are creating a Blueprint, the first thing we have to do is choose the parent class of this Blueprint. A Blueprint class can only have one parent class, but can have several child classes. The parent class is also known as the superclass, while the child class is known as the subclass.

As an example of using inheritance, imagine that we are creating several Blueprints that represent different types of weapons in a game. We can create a base Blueprint class called Weapon with everything that is common to all weapons in the game. Then, we can create the Blueprints that represent each of the weapons using the Weapon class as the parent class. The following diagram shows the hierarchy between these classes:

Inheritance is also used to define the class type of a class since it accumulates all the types related to its parent class. For example, we can say that an instance of the Shock Rifle class is of the Shock Rifle type and also of the Weapon type. Because of this, if we have a Function with a Weapon input parameter, it can receive instances of the Weapon class or any instances of its child classes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset