in reply to Beginner OOP style question

I'd second rjray's comment on flexibility. One key to productive Perl OO programming, IMO, is not to become bound by constraints other OO languages impose on you.

In the case of your search method, consider the fact that Perl lets you build hybrid methods that work as either instance (object) or class (static) methods. I know this is another one that drives OO purists wild, but I often find it useful. In the case of a search method, the possible application might be to either search within a row or across the entire set. Such a dual purpose method would look something like this:

sub search { my $invocant = shift; if (ref($invocant)) { $invocant->_set_search(); } else { $invocant->_instance_search(); } }

As you advance down the Perl OO path, take a look at ties and closures -- 2 Perl constructs that give you OO possibilities many other OO languages don't offer.

Replies are listed 'Best First'.
Re: Re: Beginner OOP style question
by dragonchild (Archbishop) on Mar 04, 2002 at 14:25 UTC
    While I have been one of the many saints to rail against my $class = ref $proto || $proto;, this is a perfect example of what a hybrid method should be.
    1. You are more perfectly emulating DWIM
    2. You can explain WHY you're doing it
    3. You actually have code that supports both invocation types
    ++ for an excellent example!

    ------
    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.