in reply to converting to a sub-class
What you're doing will work, though it may confuse people. The big question is, do you really need a DUM::DUMMY object at all, when you're going to move it to DUM::DUMMY::Whatever anyway?
If you can, I would prefer doing something like:
and have find_class_for return the right package name (and possibly require it). That way the object returned can do whatever it needs to initialize itself - it doesn't even need to be a subclass of DUM::DUMMY.sub create { my ($class,@options) = @_; my $target_class = $class->find_class_for(@options); return $target_class->new(@options); }
Another thing to keep in mind, is that this still requires you to put all the knowledge about which class to choose in the base class. That isn't really "best practice", and it's possible to avoid it, but unless you're got many classes to choose from, it's probably the simplest way to do it like this.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: converting to a sub-class
by Cagao (Monk) on Oct 20, 2007 at 18:07 UTC |