in reply to Interesting OO/package conundrum...

You could also use a class attribute on Base, rather than an instance attribute:

package Base; my %_required = ('Foo' => {one =>1, two => 1, three =>1}, 'Bar' => {one =>1, three => 1, fourteen =>1}); sub isRequired { my ($self, $attr) = @_; my $class = ref $self; return exists $_required{$class}->{$attr}; }

This way, you will store the hash of the required attributes only once.

Greetings, pike

Replies are listed 'Best First'.
Re: Re: Interesting OO/package conundrum...
by dragonchild (Archbishop) on Oct 12, 2001 at 16:49 UTC
    This is an interesting idea, and one I thought about. But, I rejected it because this would require that the base class knows about the child classes, even if it's only the names. A goal for OO is that no-one knows anything more than they absolutely have to. Have a class know something about its children is, generally, a no-no. *shrugs*

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.