Re: Delegation vs Hooks (was: Annouce: DBIx::Class, a.k.a "taking the easy way out")

[prev] [thread] [next] [Date index for 2005/07/27]

From: John Siracusa
Subject: Re: Delegation vs Hooks (was: Annouce: DBIx::Class, a.k.a "taking the easy way out")
Date: 00:39 on 27 Jul 2005
On 7/26/05 7:27 PM, Ask Bj=F8rn Hansen wrote:
> What's the difference between hooks and delegation?
>=20
> Is it just the direction the relationship starts in (hooks =3D plugin
> says "Application, I want to handle foo", delegation =3D application
> says "plugin, you handle foo")?

With any language issue, there's ambiguity based on context.  That said, I'=
d
differentiate those terms thusly:

Hooks: "When event X happens, call code Y"

Delegation: "When it comes time to do X, let Y handle it."

The distinction is that, in the "hook" case, responsibility is not entirely
delegated (see? :) to another entity.  Rather, the other entity is simply
given a chance to contribute to the process.  Delegation, OTOH, entirely
passes responsibility for a certain task to another entity.

As this post suggests:

On 7/26/05 8:07 PM, Matt S Trout wrote:
> hooks generally mean an interface to register a sub and delegation genera=
lly
> means an interface to register a class/object.

in the Perl world, code references tend to be used with "hooks", while
objects or classes tend to be used with delegation.  But IMO that's not the
important distinction between the two.  Rather, it's merely a side-effect o=
f
what does differentiate them: delegates have more responsibility, and so
most delegates are "big" (objects/classes); things connected to hooks
(hookees? :) merely "contribute," and so "small" things (code refs) often
suffice.

-John=20



(message missing)

Delegation vs Hooks (was: Annouce: DBIx::Class, a.k.a "taking the easy way out")
=?ISO-8859-1?Q?Ask_Bj=F8rn_Hansen?= 23:27 on 26 Jul 2005

Re: Delegation vs Hooks (was: Annouce: DBIx::Class, a.k.a "taking the easy way out")
John Siracusa 00:39 on 27 Jul 2005

Generated at 16:37 on 28 Jul 2005 by mariachi v0.52