in reply to Inheritance and module cross dependencies

When you need to verify whether the object you got back was a Lecturer, you could do a test something like:
if (ref($lecturer) eq "LECTURER"){ # You can do $lecutrerer->get_research(); }else{ # This dude can't research ... }
If there is only a small number of minor differences between the classes, my preferred way would be to add a bit-vector attribute to the "Teacher" class that lists capabilities like "CAN_RESEARCH".

    ..."I don't know what the facts are but somebody's certainly going to sit down with him and find out what he knows that they may not know, and make sure he knows what they know that he may not know, and that's a good thing. I think it's a very constructive exchange," --Donald Rumsfeld

Replies are listed 'Best First'.
Re^2: Inheritance and module cross dependencies
by Anonymous Monk on Jan 10, 2005 at 07:31 UTC
    No. You check if $lecturer is a LECTURER using the isa method, as in
    if( $lecturer->isa('LECTURER') )
Re^2: Inheritance and module cross dependencies
by prowler (Friar) on Jan 10, 2005 at 05:39 UTC

    Thanks for the reply.

    It's not that I want to find out which class I've got back (I'd use isa or can for that), but that I want $student->get_random_subject->get_teacher() (etc.) to give me a Lecturer for the deployment that uses Lecturers instead of Teachers, and I want to do this in the cleanest possible way.

    The bit-vector idea doesn't really work in the situation that I'm working with where an arbitrary amount of tweaking can be done between deployments (some of which will be mutually incompatible).

    Prowler
     - Spelling is a demanding task that requies you full attention.