Roles are the Perl way to ensure a class adheres to a certain design. In Linux you can OPEN a socket or a file or a device driver or whatever else. They are treated the same because they conform to a certain interface. You might want plug in different sorting algorithms without knowing the details of how they work. A role is just one language's implementation of a concept with the goals of reusing code, minimizing dependency, and designing with flexibility in mind. Sub classes and abstract classes have greater dependency because changing a parent class changes every child class. Often times you'll want to change behavior of a child object, but.. oh wait all that code is in the parent.

HackaMol - OO Perl for molecular hacking PDF explaining design

Add Dry-Run testing to classes

http://blogs.perl.org/users/ovid/2010/01/roles-without-moose.html


In reply to Re: Why Moose roles? by trippledubs
in thread Why Moose roles? by porton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.