I've finally got around to sitting down and working through perltoot and developing a few simple OO modules of my own. So far I'm having lots of fun, but I've run into a quandry over a style issue.

If we use the example from perltoot which some of you may be familiar with, or at least have available, a class is developed for managing 'Person' objects. What I'm developing is similar enough to the Person example.

In my code, I have some objects for storing data, but I'd also like a search function. My objects are identified by an integer id - because they are going into an SQL DB at this stage.

However I'd like to be able to do searches. The natural inclination is for a search method which returns a list of integers, each of I could pass to my 'fetch' method on a new object on to get the data in.

However this doesn't quite 'feel' right. For example, I need to do a $thing->new to initialize the object so I can use the $thing->search method. So I've allocated storage, created an object that didn't need to be made.

Of course this is all semantic - but it's not obvious to me in what way I've got it 'wrong', nor how to implement it 'right'.

Can provide more detail if needed, but it's basically very similar to the 'Person' class from the manpage, with some added store and fetch methods to do SQL stuff.

Would appreciate some insights from more experienced OOP programmers.


In reply to Beginner OOP style question by Tardis

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.