laziness, impatience, and hubris | |
PerlMonks |
Re: OO: Building an object of the right type based on a parameterby BrowserUk (Patriarch) |
on Mar 11, 2004 at 04:51 UTC ( [id://335708]=note: print w/replies, xml ) | Need Help?? |
Seems to that you need an Invoice-type field in your table. Then when you instantiate an instance of your InvoiceCalculator passing the Client object, it (the IC constructor) can query the invoice-type from the passed instance and bless the instance into the correct subclass. Concatenating the Invoice-type (say 'A', 'B', 'C' etc.) with it's classname to form the subclass name to bless into.
This way, adding new invoice type just requires you to create the appropriate subclass of InvoiceCalculator, and changing the type of a clients invoice just requires updating the appropriate field in that clients record in the table. You get complete flexibility and avoid hardcoded if/else cascades, and minimise code changes. Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"Think for yourself!" - Abigail
In Section
Seekers of Perl Wisdom
|
|