473,378 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

What is the name of this Python programming style

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
Jul 18 '05 #1
1 1498
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
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
21
by: godwin | last post by:
Hi all, I wanna thank Martin for helping out with my ignorance concerning execution of stored procedure with python. Now i have decided to write a web app that googles into my companies...
31
by: N.Davis | last post by:
I am very new to Python, but have done plenty of development in C++ and Java. One thing I find weird about python is the idea of a module. Why is this needed when there are already the ideas of...
10
by: Johnny Lee | last post by:
Hi, I'm new in python and I was wondering what's the difference between the two code section below: (I) class TestResult: _pass_ = "pass" _fail_ = "fail" _exception_ = "exception"
99
by: Shi Mu | last post by:
Got confused by the following code: >>> a >>> b >>> c {1: , ], 2: ]} >>> c.append(b.sort()) >>> c {1: , ], 2: , None]}
8
by: clintonG | last post by:
Every single time neophytes or converts ask about naming and style conventions what are they told by the majority consensus? The answer is "do what you prefer but do so consistently" right? Yes,...
34
by: emrahayanoglu | last post by:
Hello Everyone, Now, I'm working on a new web framework. I tried many test on the other programming languages. Then i decided to use python on my web framework project. Now i want to listen...
92
by: ureuffyrtu955 | last post by:
Python is a good programming language, but "Python" is not a good name. First, python also means snake, Monty Python. If we search "python" in google, emule, many results are not programming...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.