in reply to Re^12: RFC: OO Perl using Moo/Moose book
in thread RFC: OO Perl using Moo/Moose book

> might be considered imprecise by Wikipedia

I'm considering the Design Pattern book by the GoF as normative source, and tried to find their original definition.

And hey there is indeed a stack overflow discussion citing the books passage. ..

https://stackoverflow.com/questions/47691683/can-you-write-gof-delegation-code-examples

Alas the description is contradictory and the main reply cites ... Wikipedia. Oo

The first paragraph says that self is passed thru like in inheritance.

The second describes how the request is "forwarded". And the UML clearly shows that Rectangle->area() is returned.

WTF? ... CS is a mess!

update

See also The Gang of Four is wrong and you don't understand delegation

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^14: RFC: OO Perl using Moo/Moose book (GoF / Updated)
by choroba (Cardinal) on May 01, 2019 at 21:35 UTC
    So, the Perl Moo* equivalent would be something like
    package My::Obj; use Moo; has deputy => (is => 'ro', delegates => 'frobnicate');

    where calling $obj->frobnicate(42); would in fact call

    $obj->deputy->can('frobnicate')->($obj, 42);
    ?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Yes, looks like the WP definition of "Delegation" to me.

      But I'd say this niche is more or less (?)* filled by "Roles" in Moo/Moose ( of course with different implementation)

      Theoretically speaking. ..

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Update

      *) one difference might be that "deputy" is an attribute of the instance while roles belong to the class.

      As a side note, if you replace "deputy" with "__prototype__" and don't restrict to methods like "frobnicate" you'll have more or less the JS model of inheritance.

      That's why Self and JS are listed as examples for "Delegation".

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice