I am working on a group of OOP modules that will be used to track host status over time. There are three classes involved: Host, Event and HostGroup. The HostGroup class contains many Events and many Hosts (in actuality, subclassed versions of Host and Event). Host and Event are base classes that are intended to be subclassed, they should also have no persistance related code. I want to handle all persistance in class HostGroup.

This arrangement naturally leads to the question "If a Host/Event is not aware of persistance, how do I make sure that the stored copy is updated when I update the object in memory?" The solution I have arrived at is to have a HostGroup method, updateObject, that takes the object, method and the methods arguments as arguments:

sub updateObject { my $self = shift; my $object = shift; my $method = shift; my @returnValues = $object->$method(@_); # This method handles all updates to object store. $self->_storeObject($object); return @returnValues; }
Which seems to work and doesn't set strict screaming. Is there a problem with this approach that I am not seeing? My preliminary tests have come out fine....


TGI says moo


In reply to Managing object persistance in a container class by TGI

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.