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 ?
TIAIn reply to OO or just OOps ? by guha
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |