perl/classes/inheritance question...

Discussion in 'Perl' started by jseely13, Sep 15, 2004.

  1. jseely13

    jseely13 Guest

    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
    jseely13, Sep 15, 2004
    #1
    1. Advertising

  2. jseely13

    jseely13 Guest

    (jseely13) wrote in message news:<>...
    > 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
    =-=-=-=-=-
    jseely13, Sep 16, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maxw_cc
    Replies:
    1
    Views:
    3,116
    Martijn van Steenbergen
    Dec 21, 2003
  2. Christian Bongiorno
    Replies:
    2
    Views:
    339
    Fahd Shariff
    May 10, 2004
  3. cppsks
    Replies:
    0
    Views:
    802
    cppsks
    Oct 27, 2004
  4. karthikbalaguru
    Replies:
    9
    Views:
    1,025
  5. Daniel Pitts
    Replies:
    27
    Views:
    1,873
    Mike Schilling
    Feb 27, 2008
Loading...

Share This Page