The example you give is not appropriate for inheritence, since a Server is not a SendRecv, and instead it is more like a Server does SendRecv. This is the role model of class composition, sometimes called allomorphism (at least thats what chromatic always calls it).

You might want to take a look at Moose, and in particular the (Perl 6 style) role features. Alternately there is Class::Trait or Perl6::Roles as well (there are some other "Role" modules on CPAN, but they are either incomplete or incorrect).

As for composing the class vs. composing the object, I think this is probably something which should be dictated by the requirements. If you really need to have multiple instances all of which can do different types of servering, then use object composition. But the minute you might have several instances of one type of server, you might want to consider going with class compostion, and making custom subclasses for your needs.

As for how you can do the object composition (if you choose that route), the Class::Trait module has a stable "runtime trait composition" feature which Ovid added several months ago. Perl6::Roles has that feature as well (and in fact was the primary reason dragonchild wrote that module). Moose only recently added this feature, and it is completely undocumented (aside from a test script in the t/ directory), so unless you really want Moose's other features, I would not recommend it yet.

-stvn

In reply to Re: Class or Object composition ?? by stvn
in thread Class or Object composition ?? by rootcho

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.