We don't bite newbies here... much | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hi. rkg again, back with another OO question:
I have set of Client objects. A Client is a simple Class::DBI wrapper from a single client sql table, with a handful of extra methods. I have a InvoiceCalculator object, which upon construction takes a client object as an argument. Probably I could push this up into the Client class as ->calculate_invoice, but I haven't. Certain specific instances of Clients (say clients A1, A2 and C) get different business logic for their invoices. Fine -- I have InvoiceCalulator::Generic, and subclass it with the changes as InvoiceCalculator::A, InvoiceCalculator::C, etc. Here's my question: when I go to create an InvoiceCalculator (be it generic, or A, or C), I need to examine the client to know what kind to construct. Having a big case statement ("if client = A1 or A2 make a ::A, if client = C make a ::C, etc:) feels wrong. The other thought I had was to add the proper InvoiceCalculator class as field in the Client object. This too feels wrong: something seems strange about storing a class name (eg storing code) in a field. Feels brittle, perhaps. Suggestions? What's the right approach to build an IC object based on the specifics of the client object? Apologies if the post isn't fully clear; I've been suffering a bit of incoherence recently. Thanks for any advice -- In reply to OO: Building an object of the right type based on a parameter by rkg
|
|