Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: 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 reply to Re: OO: Building an object of the right type based on a parameter
by BrowserUk
|
|