Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Use sane Design (was Re3: OOP: Plugin Style Development)

by dragonchild (Archbishop)
on Jul 22, 2002 at 19:58 UTC ( #184211=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: OOP: Plugin Style Development
in thread OOP: Plugin Style Development

There is a very good reason to use a base class. This way, you can do something like:

die "This isn't a Display adapter!" unless $display->isa('Display::Base'); $display->doSomething(@args);

As for your concern about contracts and enforced APIs ... Perl doesn't do that. You're just going to have to make sure with all other developers that everyone agrees on an API.

IMHO, this is a "Good Thing"(tm). More communication between developers is good.

You can do a few things in the base class to provide for interface checking. Here's a canonical way to implemental a virtual function:

sub foo { my $self = shift; die "Whoever wrote '", ref($self), "' is a dork. S/He didn't overr +ide foo()!"; }
Then, when a client expects foo() to be a method and it isn't overriden, you can take a "Clue-By-Four"(tm) to the offending author. (Something along the lines of "Why didn't you follow the agreed-upon spec?!?" Of course, you need one of those to have a leg to stand on .........)

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


Comment on Use sane Design (was Re3: OOP: Plugin Style Development)
Select or Download Code
Re: Use sane Design (was Re3: OOP: Plugin Style Development)
by jk2addict (Chaplain) on Jul 22, 2002 at 20:27 UTC

    *smacks forehead repeatedly*

    I always forget the little things, repeat after me, can() and isa() are your friends. :-P

    The more it sinks in, the more I think I like the following approach: public subs (mysub) in Base that call private subs (_mysub).

    When a module uses and overrides base, it should override the private subs. This gives me enough of a warm fuzzy about preserving the public methods signature (if only in theory).

    Is there anything wrong with this approach from the standpoint of painting myself into a corner?

    Thanks for the help, and the patience.

      That works. It seems a little heavy-handed, but I can see no issues with it in my 3 seconds of comtemplation. :-)

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://184211]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2014-12-22 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (116 votes), past polls