It sounds like you may want to have multiple methods for your object's user to use, but may be able to get away with doing all the dirty work with only one method which you'd want to keep internal to your object.
like:
$obj->add_condiment('Cheeze');
Then in your object's package:
package whatever;
...
sub add_condiment
{
my $obj = shift @_;
$obj->set_property("add", "condiment", "cheeze");
}
sub add_color
{
my $obj = shift @_;
$obj->set_property("add", "favoriteColor", "blue");
}
sub set_property
{
my $obj = shift @_;
my $action_type = $_[0];
my $property_type = $_[1];
my $item = $_[2];
if( $action_type =~ m/add/i && exists $obj->{'properties'}->{"$prope
+rty_type"} )
{
push @{$obj->{'properties'}->{'$property_type'}}, $item;
}
elsif( $action_type =~ m/remove/i && exists $obj->{'properties'}->{"
+$property_type"} )
{
## loop over the items till you find what you want to
## remove, then remove it
}
else
{
die "Something unplanned happened";
}
Technically the larger method doing the dirty work could be called as a function(maybe more efficient) by explicity passing the object reference as the first arguement(i.e. <code>set_property($obj, "add", "condiment", "cheeze") )
Hope mantaining all those properties doesn't seem like such a daunting task now. :)
toodlez.
|