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
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