package Client; sub CreateInvoiceCalculator { my $self = shift; return (qw/DefaultClientIC UnusualClientIC VeryStrangeClientIC MartianClientIC/[$self->{client_type}]) -> new; } # ... my $ic = $client->CreateInvoiceCalculator;
You probably cannot totally avoid some sort of "client-type to client IC class" relation so let it be hidden inside Client class which is probably the only to need knowledge of multiple ways of invoice calculation (read: InvoiceCalculator descendants).
Or.. you can parallel your InvoiceCalculator hierarchy with a similar Client hierarchy where each Client descendant will use its own calculator. That's another story altogether.
Read "Design Patterns", really. It's full of wisdom.
In reply to Re: OO: Building an object of the right type based on a parameter
by kappa
in thread OO: Building an object of the right type based on a parameter
by rkg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |