Re: How to implement both object->method and module::function interfa ce?
[email protected] (Nick Ing-Simmons) Tue, 08 Aug 2000 20:30:38 +0000
| Newsgroups | perl.perl6.stdlib |
|---|---|
| Message-ID | <E13MG1G-0005n1-00@roam1> |
Garrett Goebel <[email protected]> writes: >What's the conventional wisdom on creating a module that supports both an OO >and non-OO interface? Are there any CORE or CPAN modules to serve as a >textbook, or is the anwser "Don't do that"? Tk does it - which can be taken either way ;-) > >I've got some code that checks the first parameter passed to see if it is a >reference, assumes any reference is an object reference... and then proceeds >accordingly. -It feels pretty sloppy, but it works. It is either fragile or slow depending how picky your validator gets. I tend to find it makes sense to not use the _same_ sub in both interfaces. Rather have sub Foo # (say) the method and sub foo # the functional interface Then implement one in terms of the other. > >Garrett -- Nick Ing-Simmons