in reply to Designing an OO program with multiple inherited classes
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Designing an OO program with multiple inherited classes
by punkish (Priest) on Dec 09, 2009 at 15:08 UTC | |
by dsheroh (Monsignor) on Dec 10, 2009 at 08:47 UTC | |
by punkish (Priest) on Dec 10, 2009 at 18:09 UTC | |
by dsheroh (Monsignor) on Dec 11, 2009 at 08:16 UTC |