Skip to content
Maarten Balliauw
← back
General 1 min read

Inheritance is evil!

edit this page

Read this on Bernie’s blog:

*“All of the pain caused by inheritance can be traced back to the fact that inheritance forces ‘is-a’ rather than ‘has-a’ relationships. If class R2Unit extends Droid, then a R2Unit is-a Droid. If class Jedi contains an instance variable of type Lightsabre, then a Jedi has-a Lightsabre.

The difference between is-a and has-a relationships is well known and a fundamental part of OOAD, but what is less well known is that almost every is-a relationship would be better off re-articulated as a has-a relationship.”*

I suggest you read the full story, as it’s very interesting! Bottom line is that you should be careful using OO inheritance, and use the Strategy pattern instead.

Maarten Balliauw

Writing about .NET, web, performance and security, since 2006.

Related posts

★ Prefer this blog on Google