The traditional way of resolving this would be with aggregation, in which Obj has a Foo and a Bar which it delegates calls to:
If you want to dip your toes into the Moose water (eeeeew...), this may be a good place to use roles, depending on what you actually want to accomplish in the real world. If you want to just pull behaviour from Foo/Bar, but still have it operate on the Obj's data, then roles are likely a good match. If you need to have independent Foo/Bar data as well as their behaviour, then it's likely that aggregation would be a more appropriate model.package Obj; sub new { ... $self->{_foo} = Foo->new; ... } sub foo { my $self = shift; return $self->{_foo}->foo(@_); }
An object is the class it inherits from, has objects it aggregates, and does roles it consumes.
In reply to Re: Designing an OO program with multiple inherited classes
by dsheroh
in thread Designing an OO program with multiple inherited classes
by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |