in reply to inheritance: constructors
IMO it's more "future facing" to use a loop on @ISA and the can method.
It enables the Object to handle multiple inheritance.
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:
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:
I also apply accessor and mutator functions for all the properties:
I set up a template and also some generic parent classes to ingherit most of the common stuff from.
It enables the Object to handle multiple inheritance.
This'll execute a "private" method to initialise the correct variables for the object.$self->$_($params) for ( map{ $_->can("_init")||()} @ISA );
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 Section
Seekers of Perl Wisdom