I've found this the best way to do it, mostly because it allows lots of generalising and lots of use of polymorphism.

I have objects of class Person, Invoice, Business etc and they all basically want the same methods called on them. Using a class method Person->newIterator actually returns an instance of PersonIterator which is subclassed from DBIterator.

PersonInterator, etc, instances are created on the fly and how they behave depends on the arguments passed by newIterator. Because all the Person, Business, etc classes are all subclassed from the same Entity class, the calling program doesn't actually have to know what class it is dealing with.

So calling: $any_Iterator = $any_class->newInterator

returns a an instance of something subclassed from DBIterator. Note DBIterator, itself, is abstract.

Then you can keep calling: $any_Iterator->nextElement;

until it returns undef.

Is this a naughty use of symbolic refs? I don't know. But what I do know is that I find this code easy to maintain easy to extend and easy to tweak.


In reply to Re: Re: OO Application Design by Nomad
in thread OO Application Design by Nomis52

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.