in reply to OO semantics quandary
Now, assuming you've been a good boy and don't have any code that actually uses an object's class name for anything, you're almost home and dry. Just add a factory method to Text::Figlet. Something like the following
There's an issue here with having to update the factory every time you add a class, but it could be worse. Hopefully by doing it this way none of your old code will break.package Text::Figlet; use Text::Figlet::Font; use Text::Figlet::Control; sub new { my $proto = new; my $class = 'Font'; if ($_[0] =~ /Font|Control/i) { $class = ucfirst(shift); } $class = "Text::Figlet::$class"; $class->new(@_); }
Also, bless that closure into a class, and give it a single method that calls the closure. Again, stuff that assumes it's a closure won't break, but you'll be able to add potentially useful methods without having to mess too much with the internals of the closure.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: OO semantics quandary
by smalhotra (Scribe) on Aug 16, 2002 at 22:02 UTC |