What is the name of this Python programming style

D

Dave Kuhlman

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
 
C

Carl Banks

Dave said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top