Look Familiar?

Ovid on 2009-07-14T22:08:59

Bernie Sumption, the author of Animator.js, has an interesting article explaining why inheritance is evil. What's really interesting about his code is that in trying to eliminate is-a relationships and replacing them with more flexible has-a relationships, he has to create a bit of extra scaffolding to make everything work. The problem is that the scaffolding is delegation and if the instance and the thing it delegates to need to communicate, you wind up with more work to do. Plus, he still has to use inheritance to make things work, thereby inviting (at a much smaller scale) some other problems with inheritance (did you implement a from() method in your DBIx::Class::ResultSource subclass? Too bad. You just overrode a method you didn't know about).

The solution, of course, would be to use roles for this. It would be cleaner and would make much of the scaffolding just go away. Plus, you get compositional safety. That being said, he may not be aware of roles, so it's not something I would call a black mark on an otherwise good blog post.


Joose

Aristotle on 2009-07-15T01:05:29

Someone tell him about Joose.