in reply to Calling chains, extends, and subclassing

First, never say new SomeClass in OO code. You can usually get away with it when writing non-OO code that merely uses OO code but you're really asking for trouble when you do it in an OO module. The problem is that if you say new Whatever in some class like Question you mean Whatever->new but if your local Question->new is already defined by the time you write the above line then you really get Question->new instead. It's 100% a bug on your part and you should never do this.

Secondly, use Ovid's aliased module to get short names. Recommend it to your users. Then they can have short names too without any extreme hacks to ISA.

use aliased 'NHB::QuizMaster::Custom::NHMCCD::Quiz'; use aliased 'NHB::QuizMaster::Custom::NHMCCD::Question'; use aliased 'NHB::QuizMaster::Custom::NHMCCD::Answer'; # Now use the Quiz->, Answer->, Question-> namespaces.

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re^2: Calling chains, extends, and subclassing
by EvanCarroll (Chaplain) on Oct 04, 2006 at 15:02 UTC
    The alias deal doesn't seem to be an apt suggestion for a few reasons,
    1. It would require me to subclass all three packages, rather than just the select ones I wanted to subclass
    2. Even if I wanted to subclass the three modules, unless subclass exported and poluted the namespace of every other package (superclass), it would seem as if I would have to have totally redundant code
    So now in the subclass, I would have something like
    ##Non redundant code
    use aliased 'NHB::QuizMaster::Custom::NHMCCD::Question';
    
    ##Totally redundant code
    sub new_question {
      my $self = shift;
      my $question = new Question( @_ ); Question->new(@_);
    
      push @{ $self->questions }, $question;
    
      $question;
    }
    

    I'm guessing that the alias doesn't affect the superclass



    Evan Carroll
    www.EvanCarroll.com

      You said "new Question" which you already know is ass. Don't be an idiot, don't do that.

      aliased isn't a structural thing - it means you don't have to use long class names in your code. It doesn't solve any subclassing or other interface problems. I suggested that you trash your entire idea to do @ISA evil and get to nirvana through syntactic sugar.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        Please do tell me how Syntactic sugar eliminates the need to statically type the class, or how I can accomplish that. (And I am thankfull that Alias would make it shorter, but I'm aiming for non-existant here) I really don't want to have to override a sub just for a new statically typed class)


        Evan Carroll
        www.EvanCarroll.com