Dear fellow monks,
I have a question to you about object-oriented design in perl.

I'm coding a log analyser. It works, but I wonder if I have made the correct object-oriented design decisions.

Maybe this question would fit better as a meditation, but since I'm right in the middle of coding it is actually of practical importance to me.

I'll start with two concrete examples and then follow with the more general question.

There is a class called "Category" that is instantiated into objects. Each object holds a pattern to match, a title for the category, a data structure for holding the statistics on the category, methods for printing out a form interface to use the category in the first place and print methods to print out statistics on the category. This makes for a self-contained object that holds data for the category, and methods for handling it in all respects.

Now, when the object does its magic it starts from the high level:

A method "process event" is called first, The "process event" method in its turn calls the "match_line" method of the object, then calls the "store_event" method. These two methods in their turn, trigger other, more low level methods in the object.

If I start looking at it from a distance it seems as if the methods can be classified as being at higher and lower levels.

In case of a class for object persistence that I wrote some time ago there seemed to be three levels: one high-level which works as a kind of interface ("$object->save"), an intermediate level that acts like a switchboard for choosing implementation methods, and an implementation level that actually does something (e.g. save to flat file system or RDBMS with certain attributes).

I know that in the world of object orientation, there are all kinds of concepts and patterns swirling around: adapters, delegation, inner classes, etcetera. So my question is: What is a good solution to this problem with methods on higher and lower levels? Is the design with all levels in the same class fundamentally wrong? How would you do it?

The goals I want to achieve are the following:

Thanks in advance,

/jeorgen


In reply to High-level methods to low-level: Do I put them together? by jeorgen

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.