in reply to A class that cannot be subclassed.
Now, you can overload all methods in the child class, but if you do you aren't really subclassing. You might as well subclass an anonymous hash. If you don't cover all bases, then the first time an inherited method is called, the program will die uglily and point out to the foolish programmer the error of his ways.package Foo::Bar; my @lineage = ('Mom', 'Dad'); @ISA = (@lineage); sub selfcheck { die "You can\'t change who I am." unless __PACKAGE__ eq 'Foo::Bar'; map { die "You can\'t change who my parents are." unless $lineage[$_] eq + $ISA[$_] } (0..(scalar @ISA - 1)); } sub DESTROY { $self->Foo::Bar::selfcheck; } sub method_name { my $self=shift; $self->Foo::Bar::selfcheck; # method stuff here } sub method_name2 { $self->Foo::Bar::selfcheck; # method stuff here }
- d
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A class that cannot be subclassed.
by kyle (Abbot) on Feb 27, 2008 at 22:53 UTC |