January 2021 Archives

Roles, h'uh, what are they good for?

What is a role? Put simply, roles are a form of code reuse. Often, the term shared behavior is used. Roles are said to be consumed and the methods ( including attribute accessors ) are flattened into the consuming class.

One of the major benefits of roles is they attempt to solve the diamond problem encountered in multi-inheritance by requiring developers to resolve name collisions manually that arise in multi-inheritance. Don't be fooled however, roles are a form of multi-inheritance.

I often see roles being used in ways they shouldn’t be. Let’s look at the mis-u…

About Jesse Shy

user-pic Perl pays for my travel addiction.