Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > What is the name of this Python programming style

Reply
Thread Tools

What is the name of this Python programming style

 
 
Dave Kuhlman
Guest
Posts: n/a
 
      05-23-2004
I'd like to learn more about this style of programming in Python.

In this style or pattern, a high level class is given an instance
(or a class from which it creates an instance), then uses that
instance to perform its tasks. A user of the higher-level class
can customize the function of that class by implementing or
customizing details in lower-level class.

I've seen it a number of times. It seems quite useful. It
provides loose coupling between a higher-level policy class and a
lower-level mechanism or implementation class. The coupling is
defined by an abstract base class which the lower level class must
implement. This loose coupling frees the higher-level policy
class from dependency on details in a lower-level mechanism class.

One example of this style is in BaseHTTPServer in the Python
standard library. The constructor to BaseHTTPServer takes a
handler class as an argument. The handler class should be
sub-class of BaseHTTPRequestHandler. So, in this example:

- BaseHTTPServer is the higher-level policy class.

- BaseHTTPRequestHandler defines the interface. Or should it be
called the protocol?

- And, the sub-class of BaseHTTPRequestHandler that I'm supposed
to implement is the lower-level mechanism class.

I think the general name for this is Inversion of Control (IoC).

Can someone tell me if this Python pattern or style has a name
among Pythonistas?

It's not unique to Python, of course, but once again Python seems
very well suited to this pattern or style.

I've been reading about PEAK (http://peak.telecommunity.com/).
PEAK supports this style of programming in a much more complex
way. Does anyone have some experience with PEAK? Is the PEAK way
better or more powerful? Learning the PEAK way seems to require
immersion in a complete Zen of PEAK. It is pretty opaque to me.
I'd be thankful for a pointer or URL to help me gain a little
understanding. I've read the tutorial and quite a bit of the PEAK
Wiki. Is there more somewhere?

Thanks for help.

Dave

--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
 
Reply With Quote
 
 
 
 
Carl Banks
Guest
Posts: n/a
 
      05-23-2004
Dave Kuhlman wrote:
> In this style or pattern, a high level class is given an instance
> (or a class from which it creates an instance), then uses that
> instance to perform its tasks.


Delegation.


--
CARL BANKS http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work."
-- Parody of Mr. T from a Robert Smigel Cartoon
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
good style guides for python-style documentation ? Fredrik Lundh Python 4 04-07-2006 06:19 AM
Need help with Style conversion from Style object to Style key/value collection. Ken Varn ASP .Net Building Controls 0 04-26-2004 07:06 PM
New style class & Old style class in Python dlo_olb Python 2 06-25-2003 01:46 PM



Advertisments