in reply to Extending objects
Instead of multiple inheritance, consider Perl roles. (Look out, here comes Moose!):
{ package Named; use Moose::Role; has 'name', is => 'ro', isa => 'Str'; } { package Aged; use Moose::Role; has 'age', is => 'ro', isa => 'Int'; } { package FooBar; use Moose; with qw( Named Aged ); }
The important part of the logic and process behind this is that each role specifies a combination of data and behavior and each class into which you apply a role consumes that combination of data and behavior. You want FooBar to have name and age attributes with read-only accessors, so you name each set of state and behavior and turn them into roles, then apply them to your class.
Moose performs something similar to the longhand code other people have demonstrated (yet without multiple inheritance and, thanks to roles, compile-time composition checking of the role validity).
|
|---|