[Zope-dev] Poor programming practice?

Steve Alexander steve@cat-box.net
Wed, 31 Jan 2001 08:58:17 +0000


Robin Becker wrote:

>
> The real problem is that ftp_channel uses a method make_recv_channel
> which uses a global class recv_channel and the recv_channel class has a
> particular method which zope wants to override. How ought this kind of
> situation to be handled more cleanly?

I haven't looked at the code, so the following is based only on your 
paragraph above, and probably doesn't apply to the real classes we're 
talking about :-)


This sounds like a classic application of the Factory Method pattern.

In brief, you have the ftp_channel class. Its instances have a 
make_recv_channel method. This is the Factory Method. It returns 
whatever is appropriate for a recv_channel.

You create a subclass derived fom ftp_channel called perhaps 
zope_ftp_channel, which defines a new make_recv_channel method. This new 
method does whatever Zope needs for making the recv_channel.


The other option is to use the Abstract Factory pattern. In this case, 
you'd pass the constructor of the ftp_channel class a bound method (or a 
function) that returns the appropriate kind of recv_channel.

You could let an ftp_channel instance know about this bound method (or 
function) by other means instead, rather than passing it in the constructor.


Both patterns are discussed in the infamous "Gang Of Four book" Design 
Patterns: Elements of reusable object-oriented software, Gamma, Helm, 
Johnson and Vlissides.

There will be explanations on the web somewhere too, no doubt.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net