I think I see what you're getting at. Personally, I'd write the constructor like so:

package Base_class; ## new (args:hashref) : Object_ref # # create a new object, then initialize it from class-specific # defaults and/or argument values. # sub new { my $O = bless {}, shift; my $args = shift; my $defaults = $O->_defaults; ## iterate over the keys in %$defaults, because those are all ## we really care about: for $k (keys %$defaults) { $O->{ $k } = (defined $args->{$k}) ? $args->{ $k } : $defaults->{ $k }; } return ($O); } package Subclass_1; @ISA = qw( Base_class ); ## _defaults (nil) : hashref # # return a hash of default values for objects of this class # sub _defaults { ## this is basically a static variable for the class. i ## define such things at runtime, but that's just a personal ## taste. if ( ! defined $DEFAULTS ) { $DEFAULTS = { 'attr1' => 'val1', 'attr2' => 'val2', 'attr3' => 'val3', }; } return ($DEFAULTS); }

That gives you the freedom to create as many subclasses as you want, each with its own signature of attributes. Each subclass will only accept values from its own signature, and every object will be fully initialized to its own signature by the time the ref leaves new().


In reply to Re: Re: Re: OO Perl and Design Issues by mstone
in thread OO Perl and Design Issues by jonjacobmoon

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.