in reply to Re: Conceptual Question About Classes and SubClasses
in thread Conceptual Question About Classes and SubClasses

Thank you for your reply. If I added the additional information, would it change the way you lean:
I would like my "subclass" of CLASS::A and CLASS::B to share a common set of methods. My project specific methods should work independently of which class they are working on. For instance, whether or not I have A or B, i would like to X->validate them... If I sub-classed them, I think I would have to write two validate methods, in each subclass. I was trying to avoid that.
Again, thanks for the help... I am not a programmer by trade, I am a chemical engineer so need some conceptual help!

Replies are listed 'Best First'.
Re^3: Conceptual Question About Classes and SubClasses
by jethro (Monsignor) on Aug 20, 2009 at 16:49 UTC
    I believe the right approach is to have a method in X that validates whatever is to validate in X. If you can make that method generic, so that it would work for A and B too, even better

    Any subclasses for which X->validate does everything that is to do are finished now. Any subclass that has to do something more would have their own validate method. That method would then call the validate method of the superclass ($self->SUPER::validate) and if that returns ok, validate the additional stuff of the subclass.

    As you can see, you probably need a validate method in A and in B, BUT you don't need to write any code twice.

      Thanks!