What is the name of this Python programming style

Discussion in 'Python' started by Dave Kuhlman, May 23, 2004.

  1. Dave Kuhlman

    Dave Kuhlman Guest

    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 Kuhlman
    Dave Kuhlman, May 23, 2004
    1. Advertisements

  2. Carl Banks

    Carl Banks Guest

    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.


    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
    Carl Banks, May 23, 2004
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Roedy Green
    Jan 2, 2006
  2. ding feng
    ding feng
    Jun 25, 2003
  3. Bobby Chamness
    Joe Smith
    Apr 22, 2007
  4. Ken Varn
    Ken Varn
    Apr 26, 2004
  5. Jack-2
    Dec 24, 2003

Share This Page