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:
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....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; }
TGI says moo
In reply to Managing object persistance in a container class by TGI
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |