Thankyou! I hardly expected such an insightful reply so quickly!

What you've said makes loads of sense. Firstly, regarding the class method, I give myself a big forehead slap, and say 'Doh' for that. I should have made that intuitive leap.

Secondly the search. Again, this makes lots of sense. I did think of this but initially discarded it, since my backend is SQL and I thought this would be costly in time and memory (each object could be several K worth of text).

But after reading your words and some reflection, I think this is mitigated by two factors:

  1. Searches should not return that many results. A hard limit can be imposed if necessary.

  2. Better, if I change my implementation of the 'fetch' method, which pulls from the SQL, and my AUTOLOAD proxy methods for the data, I can initialize a bunch of objects from a search, but not actual load a single byte of data from the database backend until a data method actually requests it.

This is some real work, but I think it's doable, and would be massively elegant.

BTW, just some background on my little project, may be interesting to you or others, and comments are as always welcome. I'm designing my modules to support on online journal, the 'dear diary' kind.

I have implemented this several times over the last few years, the earliest being a .BAT file and a bunch of editor macros. The most recent and still in use is a PHP version.

So to bring it into the OOP context, each 'Entry' object holds some meta information like author (probably will be another object), date written and so forth, plus the actual text.

The part that made me think it would be an ideal bench test for my OOP learning experience was that I wanted to implement a DBM backend later, to replace the SQL backend. If done right, I simply copy Backend.pm-DBM over Backend.pm and suddenly my appliction no longer needs an SQL database. I also don't need to touch Entry.pm, or any of the other modules.

This comes from a pet peeve of mine, the amount of free software out there which requires a MySQL server, yet doesn't really need one. I'd like to release something that gives the user a choice.

Anyway, that's enough raving about my project, I'm off to go and think about how to implement my load on demand Journal Entry objects.

Thanks again!

Update 2002/3/3

Both the class search method, and the on-demand fetching are both working a treat.

For the latter, basically I just renamed my fetch method to real_fetch, and made a new fetch method, which simply sets an fetch_ID field in the object.

When my AUTOLOAD proxy method gets called when something tries to access the object data, the method sees that it is necessary to fetch it, and passes the fetch_id to the real_fetch method, which goes out to the backend to do the grunt work.

Great! With the above working, the search class method can return umpteen objects back to the program, without incurring any database access for each one. As soon as the program tries to get data out of them, it is fetched automatically.


In reply to Re: Beginner OOP style question by Tardis
in thread 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.