Background:

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

In reply to OO or just OOps ? by guha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.