Choosing this type of implementation, it will be easy to extend the solution by a new commenttype: Only a new derived class is needed.
You choose a derived class to instantiate, according to a comment in the data. That's fair enough, but it doesn't explain why you need to build a list of all possible derivable types? There is presumably a relationship between the value of the comment, and the name of the derived class to instantiate?
All that knowing what is available achieves, is the ability to take a slightly earlier exit if you read a comment that requires a class that isn't available. But the additional complexity required to decide not to try and instantiate an instance of an unavailable class doesn't justify itself when simply making the attempt to instantiate the instance tells you the same information for free.
Eg.
my %derived = listOfDerivedClasses( 'Element' ); while( <SQL> ) { my( $type ) = m[...]; die "Derived type $type not available" unless exists $derived{ $ty +pe }; push @instances, $type->new(); }
Versus:
while( <SQL> ) { my( $type ) = m[...]; my $inst; eval{ $inst = $type->new(); 1 }; die "Derived type $type not available:'$@'" if $@; push @instances, $inst; }
I guess my question is, does the extra complexity of providing introspection buy you something that is otherwise unavailable; or provide for it in some way that is sufficiently better to justify the cost?
In reply to Re^3: OO-Perl Question: How Do I get a List of derived Classes for a Base Class?
by BrowserUk
in thread OO-Perl Question: How Do I get a List of derived Classes for a Base Class?
by BluePerl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |