© Casey Hardman  2020
C. HardmanGame Programming with Unity and C#https://doi.org/10.1007/978-1-4842-5656-5_11

11. Inheritance

Casey Hardman1 
(1)
West Palm Beach, FL, USA
 

A major staple of object-oriented programming is the concept of inheritance. Inheritance is when types of data (such as classes) adopt fields – such as variables and methods – from another data type.

Say you have two classes that both share nearly all the same fields, but one has an extra field or an extra method that the other does not have. Coding each one separately is tedious. They behave in the same way for the most part. If you want to change something that both classes have, you need to make the change twice and make sure it’s consistent. It becomes even more of a problem ...

Get Game Programming with Unity and C#: A Complete Beginner’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.