in reply to Base class constructor that blesses into subclass
Eg, an abstract Word class may have variables english and greek, but its child class, Noun, may need nom_singular, whereas child class, Verb, may need to be constructed with infinitive.
Perhaps at the moment you can't imagine, say, your Interrogative and Declarative classes diverging like that, but for the sake of expansion, I'd be cautious of blessing into a subclass.
I forgot to say, an alternative might be to test the string to decide which kind of subclass you need, then create an instance of that subclass by calling its own constructor, but in each of the constructors for the subclasses, have a call to the parent's constructor (like super in Java). This is what I did, and the PerlMonks very kindly showed my how to do it.
|
|---|