in reply to On Perl Objects!
As have already figured out in your Q5, what you usually want to do is create something that contains three objects. Very typically this is a hash in Perl, especially if each element object fulfills a role. So Human->new() may call Arm->new() and Leg->new() twice each; and put the resulting members in its fresh new $self->{right_arm}, $self->{left_arm}, $self->{right_leg}, and $self->{left_leg}.
You would then access the nested objects via indirection, which is a bit slower but not significantly so for most purposes. For example:
$person = Human->new(); $person->{right_arm}->grasp("banana"); # not through accessor $person->get_right_arm->grasp("banana"); # through accessor # or, you might write accessors like this too if you think they'd be u +seful: $person->arm("left")->grasp("orange");
What you should write depends on what you really need. What do your objects represent?
|
|---|