By Shawn Moore (sartak) from Tsukuba.pm
Date: Friday, 11 September 2009 14:20
Duration: 40 minutes
Language: English
Tags: moose moosex parameterized role roles
You can find more information on the speaker's site:
Roles are an excellent object-oriented tool both for allomorphism and for reuse.
Roles facilitate allomorphism by favoring "does this object do X" versus "is this object a subclass of X". You often care more about capability than inheritance. In a sense, roles encode types better than inheritance.
Roles also provide an excellent faculty for reuse. This effectively eliminates multiple inheritance, which is often the only solution for sharing code between unrelated classes.
Roles can combine with conflict detection. This eliminates accidental shadowing of methods that is painful with multiple inheritance and mixins.
Parameterized roles (via MooseX::Role::Parameterized) improve the reusability of roles by letting each consumer cater the role to its needs. This does sacrifice some allomorphism, but there are ways to restore it.