Extending Methods Vs Delegates

Alex Martelli aleaxit at yahoo.com
Wed Mar 22 00:30:19 EST 2006


vbgunz <vbgunz at gmail.com> wrote:
   ...
> Python in a nutshell explains on page 80: Delegating to superclass
> method (5.1.6.2 in the ebook) that the first example above (extending

I'm not using "delegate" in any specialized technical sense, e.g.
(picking from a google search on [define:delegate]), "person designated
to act for or represent another or others".  Here, object, not person,
of course.  What the Learning book chooses to call ``delegate'' is
commonly known in the programming world by the (lousy) name "Template
Method design pattern" (I like to call it "self-delegation", but that's
just me).

I regret Ascher and Lutz's choice to muddy the waters by implying that
"delegate" has this very specialized meaning...

> above, what is the purpose of calling a sub class method from a super
> class instance? What is the application to such a design? The reason I
> ask is because it is honest to god confusing and I've heard of
> delegates before...

Forget the naming: the purpose of the Template Method design pattern is
to abstract the structure in the superclass while allowing subclasses to
see to the details.  A great pattern (w/a lousy name).  Several of my
presentations (you can find them in the english-language half of
www.aleax.it) touch on design patterns in Python.  I guess I'll have to
write a real essay about that sooner or later -- meanwhile, try to make
do with my presentations, my posts
<http://groups.google.com/groups?as_q=&num=50&scoring=r&hl=en&as_epq=tem
plate+method&as_oq=&as_eq=&as_ugroup=&as_usubject=&as_uauthors=alex+mart
elli&lr=&as_drrb=q&as_qdr=&as_mind=1&as_minm=1&as_miny=1981&as_maxd=21&a
s_maxm=3&as_maxy=2006&safe=off>, and what you can find by google search
on ["template method" design pattern]...


Alex



More information about the Python-list mailing list