kevinlyda has asked for the wisdom of the Perl Monks concerning the following question:
but have the Transaction class return a sub class of Transaction. let's say TransactionA or TransactionB. now i assume i would do something like:$work = new Transaction($request)
although i suppose Transaction isn't really a superclass anymore. anyway i guess my question really boils down to, "what is a clean way of creating an object of differing types based on data passed to a constructor?"sub new { my($r) = @_; if (&test($r)) { return new TransactionA($r); } else { return new TransactionB($r); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: oo perl - using the super-class
by tilly (Archbishop) on Oct 03, 2000 at 15:07 UTC | |
by kevinlyda (Initiate) on Oct 03, 2000 at 18:50 UTC | |
by merlyn (Sage) on Oct 03, 2000 at 18:52 UTC | |
by tilly (Archbishop) on Oct 03, 2000 at 18:53 UTC |