From: Scott L. <sla...@th...> - 2002-09-04 18:28:52
|
Something I've found annoying is that some classes are implemented as scalar references. Say I want to subclass Wx::MenuBar. Because it is a scalar reference instead of the normal hash reference, I can't do this: package MyMenuBar; use base qw(Wx::MenuBar); sub new { my $class = shift; my ($super, $self); $super = $class->SUPER::new(); $self = bless $super, $class; # the class is a scalar reference, so perl dies $self->{'mydata'} = "some string"; ... } I can implement an accessor, or put the Wx::MenuBar into a hash, but it's tedious and a scalar reference is unexpected. (Plus out of laziness I prefer to use things like Class::Accessor::Fast to autoload the accessors.) As said in "Object Oriented Perl" by Damian Conway, "You almost never see a Perl class based on a blessed scalar value. ... "...in those few cases where an object _does_ possess a single value, it's just as easy to go with a more familiar hash-based implementation, using only a single entry.... ...has the advantages of: Familiarity to the implementer. ... [probably not relevant to you] Familiarity to others. ... [relevant to me :)] Readability. ... [not really relevant here] Extensibility in subclasses. ... [WHAT I'M FINDING ANNOYING!!] " I think since wxWindows philosophy/API is very object-oriented, that perhaps (unless there is a technical reason forbidding it) those classes should be hash refs. |