上QQ阅读APP看书,第一时间看更新
Inheritance
Another important principle of object-oriented programming is inheritance. Let's say our game had four different kinds of weapons: Pistols, machine guns, sniper rifles, and laser cannons. A lot of the functionality of those guns would be the same. They would each have ammo, damage, accuracy, and so on. Instead of having to duplicate all that code, they could all inherit the basic functionality of a weapon and change the properties they needed to to get their specific functionality.