Even after musing over damian's insights, dare i say that OO programming in perl could still be implemented much more cleanly/elegantly (IMHO).
On that note, i am searching for enlightened monks' opinions on the best way to implement class data such that it may be cleanly inherited by subclasses.
here are (my) 2 top contenders:
my $_Class_Data = "private stuff"; ... sub Class_Data () { return $_Class_Data; }
On the surface this appears the best solution: it is inherited, and may be subclassed; though therein lies its downfall - a subclass is obligated to provide its own implementation of Class_Data if it wants to expose its own version of $_Class_Data. not an ideal solution when you want a subclass to provide its own $_Class_Data without requiring the subclass author to provide an implementation.
my $_Class_Data = "private"; ... # constructor sub new { my $class = shift; return bless( { _Class_Data => \$_Class_Data, # other init... }, $class ); }
This approach works fine if you only want to provide $_Class_Data only from the class in which $_Class_Data was first declared, *and* if you provide an accessor method for it, or note it as "public class data" in the object hash. If you really want to have each class have its *own* version of $_Class_Data, you're out of luck.
So, opinions anyone? I can see that it wouldn't be too difficult to provide a Class_Data method which accessed/ manipulated the namespace of the calling object's classname, but that's *really* pushing the limits of what most people accept as "OO abstraction".
In reply to opinions on the best way to inherit class data by d_i_r_t_y
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |