This sounds like the question of should i inherit from a base class, or should i include an instance of some other class in my class. What i mean is, if you have a calendar class, and you want calendar functionality in a basically unrelated class, such as some specialized DB class, you probably dont want to have the DB class inherit from the Calendar class, you probably want an instance of the Calendar class in the DB, which then has a well defined interface.
package MyDBClass; use MyCalendar; sub new { my $class = shift; ... my $self = ...; ... $self->{'_calendar'} = MyCalendar->new(); ... return bless $self, $class; } sub Calendar { return $self->{'_calendar'}; } ...
Then you have a calendar as a data element of your DB class, and you can do things like:
my $db = MyDBClass->new(); $db->Calendar()->CalendarFunction(...);
Now there are other, more sophisticated ways to deal with the calendar in the DB, but this should illustrate the point.

The moral is, if a class wants some other packages functionality, it doesnt have to be a child class, it can just use the other class.


In reply to Re^3: OO, inheriting functions from other packages by shemp
in thread OO, inheriting functions from other packages by sschneid

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.