in reply to Re^3: OOP - Constant Vs. Subroutine
in thread OOP - Constant Vs. Subroutine
Not really, Class->constant won't inherit from Superclass->constant ; it needs to be defined in both.
however $classObject->constant will inherit constants from superclass as class object methods , and allow the ability to override
so...
package aaa; use constant HELLO=> 'world'; use constant PUNCTUATION=> '!'; sub new { #std constructor here } package bbb; our @ISA= qw( aaa ); use constant HELLO=> 'universe'; package main; my $a= aaa->new(); my $b= bbb->new(); print "\n Hello " . $a->HELLO . $a->PUNCTUATION ; print "\n Hello " . $b->HELLO . $b->PUNCTUATION ;
will get you
Hello world! Hello universe!
but bbb->PUNCTUATION doesn't exist
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: OOP - Constant Vs. Subroutine (super constant!)
by tye (Sage) on May 12, 2007 at 18:38 UTC | |
by 2xlp (Sexton) on May 12, 2007 at 18:54 UTC |