in reply to has-a in Perl

The 'A "has-a" B' relationship is implemented by creating a member of class B within an object of class A. They are generally disparate types.

What you are describing sounds like you want a parent class to be aware of a derived class, and that doesn't sound like a Good Thing to me. What are you trying to accomplish, in slightly more concrete terms?


Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: has-a in Perl
by skazat (Chaplain) on Apr 18, 2005 at 20:06 UTC

    I'm basically just trying to make a method of my base class in a separate module (file) - but the method needs methods of the base class to work correctly.

    It would be cool to be able to call this new method in my program via the base class or the separate module; So if I want to work with just Checkboxes, I got it, if I want to work with all my widgets, got that too - not a good idea?

     

    -justin simoni
    skazat me

      It would be cool to be able to call this new method in my program via the base class

      That's what subclassing does: you can call any method from the base-class, and if the subclass implements or overrides that method, the subclass's method will be called.

      package Base; sub method1 { my $self = shift; $self->method2(); } sub method2 { print "Base\n"; } package Sub; @ISA = qw(Base); sub method2 { print "Sub\n"; } package main; Base->method1; Sub->method1; __END__ Base Sub