guha has asked for the wisdom of the Perl Monks concerning the following question:
Recently I bought myself "Object Oriented Perl" by the esteemed Damian Conway. Interesting reading I thought, but I know the old saying that reading isn't knowing.
So I thought the the next project would be OO, getting my feet wet and all that.
The Project:The project is what you might call an order confirmer, that gets information from SQL-databases, generates nice output in MS Word and automatically sends the confirmation to client as either Fax or PDF.
The Problem:I have done similar, in some sense, imperative program where the data has been organized as a treelike structure in a hash, and where I have showed a reference to this hash around to the various subroutines. This has worked well the main feature being short argument lists, but I imagined that OO would be safer and prettier.
In the non-OO solution I would have something like this
Most of the toplevel keys of the hash maps *almost* to tables in the database, however the real app is much more complicated than the example below suggests, so relying more on the database is not an option.
%obj = ( CFG => { DSN => 'test', PDF => 'MyPDFdriver', }, CLIENT => { 10101 => { Name => 'Client Name1', Adress => 'Adress1', Phone => '555-7865', Media => 'Mail', }, 10102 => { Name => 'Client Name2', Adress => 'Adress2', Phone => '555-7866' Media => 'Fax', }, }, ORDER => { 2ZXWEQ => { CLIENT => 10101, Info => 'Pix proj 123', ITEMS => [VX12345, VX12346], }, 3ZSIUY => { CLIENT => 10101, Info => 'Something else', ITEMS => [VX12347, VX12348], }, }, ITEM => { VX12345 => { ORDER => 2ZXWEQ, TYPE => HW33, Price => 123, }, VX12346 => { ORDER => 2ZXWEQ, TYPE => HW33, Price => 123, }, VX12347 => { ORDER => 3ZSIUY, TYPE => HW34, Price => 155, }, VX12348 => { ORDER => 3ZSIUY, TYPE => SW12, Price => 1203, }, }, TYPE => { HW33 => 'foo manipulator', HW34 => 'bar stimulator', SW12 => 'baz simulator', }, ); so print $obj->{TYPE}{ $obj->{ITEM}{VX12348}{TYPE} } would yield baz stimulator
So I figured that making a class of each of the top level hash keys and somehow make it act as a container for instances of that class.
However my limited OO knowledge can't seem to grasp how to get or set the different attributes of a parallell branch in the tree structure for instance.
Should I have organized the data differently ?
Is it altogether a bad case for OO ?
Does anyone have any ideas ?
TIA
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: OO or just OOps ?
by merlyn (Sage) on Sep 23, 2002 at 14:14 UTC | |
by guha (Priest) on Sep 23, 2002 at 14:46 UTC | |
by blm (Hermit) on Sep 23, 2002 at 18:10 UTC | |
by Anonymous Monk on Sep 24, 2002 at 02:30 UTC | |
|
Re: OO or just OOps ?
by BUU (Prior) on Sep 23, 2002 at 13:29 UTC | |
|
Re: OO or just OOps ?
by Ryszard (Priest) on Sep 23, 2002 at 15:37 UTC | |
by guha (Priest) on Sep 23, 2002 at 21:32 UTC | |
by Anonymous Monk on Sep 24, 2002 at 03:00 UTC | |
|
Re: OO or just OOps ? (Joke/OFFTOPIC)
by Flexx (Pilgrim) on Sep 23, 2002 at 15:32 UTC |