perl/classes/inheritance question...

J

jseely13

in c++ when you create a superclass and subclass, there is some way
you can define the superclass such that it has an empty/undefined
method. any children of this class are required to both have and
define this method. i wish i could remember what this is called...

for ex:

parent-class:
sub do_something() {
}

child-class 1:
sub do_something(){
x++;
}

child-class 2:
sub do_something(){
x--;
}

anyway, is there a comparable thing in perl? it would be useful
atm...

TIA,

-- john
 
J

jseely13

in c++ when you create a superclass and subclass, there is some way
you can define the superclass such that it has an empty/undefined
method. any children of this class are required to both have and
define this method. i wish i could remember what this is called...

pure virtual functions...

from the looks of it, perl doesn't do it... and it also looks like
perl ppl in past posts haven't fully understood them. don't tell me
that because all methods in perl can be overridden that there's no
point in pure virtual functions...

a pure virtual function is useful when a subclass must do something
but the parent doesn't know what the child needs to do specifically.
so if you're writing some type of parser, you can say 'any child must
be able to .parse(), but i have no idea what that will consist of'

the other great thing about that is that it keeps other coders from
breaking your code if they go to add a new subclass, b/c they are
boxed in...

=-=-=-=-
parentclass
pure virtual function parse
....
....
if (...) {
x = new subclassA; }
elsif (...) {
x = new subclassB; }
elsif (...)
....
....
extractedData = x.parse(data) # u can't write a subclass
# that won't work here
=-=-=-=-=-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top