D
Derek Basch
Hello all,
I am trying to do class aggregation properly in perl. I was wondering
what the best practices for accessing a container objects state from
the aggregated objects is.
For instance this is what I came up with:
-----------------------------------------------------------------------
use strict;
use warnings;
package Member_dev;
use Membership_dev;
sub new {
my $class = shift;
my $member_identifier = shift;
my $self = {
'address' => "yo momma's house"
};
bless ($self, $class);
$self->{'membership_dev'} = Membership_dev->new($self);
return $self;
}
package Membership_dev;
sub new {
my $class = shift;
my $self = {
'member' => shift
};
bless ($self, $class);
return $self;
}
sub suspend {
my $self = shift;
print "Address $self->{'member'}->{'address'} is suspended!";
}
package main;
my $member = Member_dev->new();
$member->{'membership_dev'}->suspend();
-----------------------------------------------------------------------
As you can see I am passing the member object reference to the
aggregated membership object. Then I can access the container objects
state information from the aggregated object. Is this a good idea? Is
there a better way to do this?
Thanks for the help,
Derek Basch
I am trying to do class aggregation properly in perl. I was wondering
what the best practices for accessing a container objects state from
the aggregated objects is.
For instance this is what I came up with:
-----------------------------------------------------------------------
use strict;
use warnings;
package Member_dev;
use Membership_dev;
sub new {
my $class = shift;
my $member_identifier = shift;
my $self = {
'address' => "yo momma's house"
};
bless ($self, $class);
$self->{'membership_dev'} = Membership_dev->new($self);
return $self;
}
package Membership_dev;
sub new {
my $class = shift;
my $self = {
'member' => shift
};
bless ($self, $class);
return $self;
}
sub suspend {
my $self = shift;
print "Address $self->{'member'}->{'address'} is suspended!";
}
package main;
my $member = Member_dev->new();
$member->{'membership_dev'}->suspend();
-----------------------------------------------------------------------
As you can see I am passing the member object reference to the
aggregated membership object. Then I can access the container objects
state information from the aggregated object. Is this a good idea? Is
there a better way to do this?
Thanks for the help,
Derek Basch