|laziness, impatience, and hubris|
OO Design Questionby Sixtease (Friar)
|on Mar 13, 2008 at 07:37 UTC||Need Help??|
Sixtease has asked for the
wisdom of the Perl Monks concerning the following question:
I'm making a computational-linguistic application (finding clauses in sentences). The whole thing is a perl module and it has a "train_model" function, which will accept training data and train and save a model. The model itself is pluggable. It's a class, the name of which is in a configuration file or provided to the "new" method. The training itself is then delegated to the model class by calling its train method.
However, the model may need to peek at the various configuration I have stored in the main object. So, when calling the model's train method, I would like its first parameter to be actually the main object. The model class is not instantiated (it needn't even provide a "mew" method - just "train" and "tag") and I only have the name of the class.
I could either make the object think he's an instance of the model class (by blessing its copy or setting local @ISA) or I could explicitly call the train function by no strict 'refs'; &"$model_class::train"($self, training_data) or make a change to the overall design.
What do you think?
A skeleton of the layout:
use strict; use warnings; print "Just Another Perl Hacker\n";