Thursday, October 11th, 2007
When we wrote about Bernard Sumption’s Animator.js there was a lot of “interest” in Bernies position that OO inheritance sucks.
Bernie decided to fuel the fire and expanded his thoughts, explaining how the strategy pattern is in fact your saviour ;)
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.
The article takes the world of Jedi and then writes a real example using Balls and BouncingBalls. He also explains why he thinks that Flash’s DisplayObject hierarchy is good, and that EventDispatcher is bad.
Posted by Dion Almaer at 10:10 am