[Pdx-pm] Poll: traits
Marvin Humphrey
marvin at rectangular.com
Sat Nov 19 12:18:07 PST 2005
On Nov 19, 2005, at 11:17 AM, Ovid wrote:
> package FamilyMember;
> use Class::Trait
> TSpouse => { exclude => ['fuse'] },
> TBomb => { exclude => ['explode'] };
>
> And now FamilyMember->can('explode') (from TSpouse) and
> FamilyMember->can('fuse') (from TBomb).
So... without Class::Trait, you can get superficially similar
behavior if Bomb exports 'fuse' and you start off FamilyMember like
this:
package FamilyMember;
use base qw( Spouse );
use Bomb qw( fuse ); # override the fuse() in Spouse
But you'd have to know that there was a conflict there before you
could resolve it. The advantage of Class::Trait is that you don't
have to keep so many things in your head at one time when designing
classes with multiple inheritance. It will fail catastrophically
when there are conflicts rather than silently do the wrong thing
every once in a while.
package FamilyMember;
use base qw( Bomb Spouse ); # not good
Would it be fair to describe a Trait as a base class that doesn't
allow its methods to be overridden without an explicit directive?
Marvin Humphrey
Rectangular Research
http://www.rectangular.com/
More information about the Pdx-pm-list
mailing list