Roles Talk

Wednesday I gave my roles talk at OSCON (please rate it if you've seen it) and, as usual, I came away learning things from the questions. My favourite, by far, was Perrin Harkins asking whether or not we at the BBC found method conflict resolution to be our greatest win when we switched one system over to roles instead of inheritance.

Usually people ask questions that I've either heard before or have considered, but this was a new question for me and I tried to answer on the fly, trying to make sure that I was accurately reflecting our experience. In the end, I think our biggest win was not from method conflict resolution, but in tearing apart the inheritance hierarchies and creating small, cohesive units of behaviour. When you're inheriting from the Auditing class[1] because you only need that one method, you're potentially slurping in a lot of behaviour which you do not need, a potential source of bugs. When you break Auditing out into a role, you can consume it and either exclude the methods you don't need (quick hack) or break that one method you need into a separate role (a better strategy). In short, you don't slurp in behaviour you don't need and thus have a system far more likely to model your actual problem.

It's great when intelligent questions teach you new things.


1. Yes, that's an awful class name, but if you see the entire talk, you understand why it's there.

Leave a comment

About Ovid

user-pic Have Perl; Will Travel. Freelance Perl/Testing/Agile consultant. Photo by http://www.circle23.com/. Warning: that site is not safe for work. The photographer is a good friend of mine, though, and it's appropriate to credit his work.