Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
IMO it's more "future facing" to use a loop on @ISA and the can method.
It enables the Object to handle multiple inheritance.
$self->$_($params) for ( map{ $_->can("_init")||()} @ISA );
This'll execute a "private" method to initialise the correct variables for the object.
As a rule, I pass all Parameters for the function inside a hashref called $params, it makes for easier coding and ledgibility.
I generally have a class property called @manifest, listing the object properties and use a line like:
$self->{$_ns . $_} = $params->{$_} || '' for @manifest;

Where $_ns is the namespace as all the gubbins is stored in one hash, it's best not to overwrite stuff.
I use a class property like this:
my $_ns = __PACKAGE__; 
For I find there are times when __PACKAGE__ doesn't want to play.
I also apply accessor and mutator functions for all the properties:
sub get_spong() { $_[0]->{ $_ns . 'spong' } }
And because all of this is labour-intensive and boring,
I set up a template and also some generic parent classes to ingherit most of the common stuff from.

As a rule of thumb Perl OO is tricky, because it's Perlish OO.
You can rewrite OO from first principals.
Perl OO can be clunky: it mirrors the developers understanding of OO principals since Perl is so liberal.

--

Brother Frankus.

¤


In reply to Re: inheritance: constructors by frankus
in thread inheritance: constructors by Basilides

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (17)
    As of 2014-07-30 17:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (237 votes), past polls