next prev What Works Slide #94

Delegation

Inheritance is an 'isa' relationship

Delegation is a 'hasa' relationship

Solves a lot of problems inheritance has trouble with.

If you're using a lot of multiple inheritance, consider delegation

    sub foo {
        my $self = shift;
        return $self->{some_other_object}->foo(@_);
    }

Or use Class::Delegation, another Damian Conway production.


next prev ToC Copyright © 2002-2003 Norman Nunley & Michael G Schwern