Should we always use inheritance?

Inheritance and polymorphism are both very useful and really show off the power of object-oriented programming. However, in some circumstances, inheritance can cause more problems than it solves, and therefore, we should bear in mind a few rules of thumb when deciding whether or not to use it.

Could the same thing be achieved with a simpler solution?

Let's say we want to make a more powerful Enemy object; it will have the same behavior a regular Enemy object will have but with more health. One possible solution would be to derive a new class PowerEnemy from Enemy and give it double health. In this solution the new class will seem extremely sparse; it will use the functionality from Enemy but with one different value. ...

Get SDL Game Development 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.