I think you should keep existing definitions of Foo and Bar. There's no reason to change them. I might implement a FooBar class like this though:
and use it like this:package FooBar; our @ISA = qw/Foo Bar/; sub new { my ($class, %args) = @_; bless { map %$_, $class->Foo::new(%args), $class->Bar::new(%args), }, $class; }
package main; my $a = FooBar->new(name => 'Zoid', age => 55); printf "name: %s, age: %s\n", $a->name, $a->age;
As long as there are no naming conflicts, this should be good. If there are naming conflicts you might choose to override the access method.
Also I don't like your directory structure. I usually go down the inheritance hierarchy which only works for single inheritance. Truck/FireTruck.pm. If FireTruck is both a Truck and a Fire, I wouldn't name it FireTruck/Fire.pm and FireTruck/Truck.pm. You may find that you can think of one base class its true base and the other is like a role. But better yet put them all at the same directory level.
In reply to Re: Extending objects
by youwin
in thread Extending objects
by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |