Protected Methods and Python
James M. Stern
stern at itgssi.com
Mon Apr 14 21:31:05 CEST 2003
On Mon, 14 Apr 2003 20:19:49 +0200, Dirk Gerrits <dirk at gerrits.homeip.net>
> Jan Dries wrote:
>> Don't worry too much about protected methods. Bjarne Stroustrup, creator
>> of the C++ language, considers them to be a design mistake, and now
>> regrets they were ever added to C++. See "The Design and evolution of
>> C++" by Bjarne Stroustrup, page 302.
>> Java and I assume Ruby as well simply copied the concept from C++.
> I don't have the book with me, but are you sure it wasn't protected DATA
> members that Bjarne regretted?
It was. From _The Design and Evolution of C++_, Section 13.9 (Protected
"Fortunately, you don't have to use protected data in C++; 'private'
is the default in classes and is usually the better choice. Note that
none of these objections are significant for protected member
*functions*. I still consider 'protected' a fine way of specifying
operations for use in derived classes.
That paragraph is near the end of the section, and "these objections"
refers to arguments just made against protected data.
Admittedly, the next paragraph says that 'protected' "overcame my better
judgment [...]" but I think he means (data) members there.
... As an aside, I view every Python method I write as intended either
for the world, for this class and derived classes only, or for this
class only. In short, as public, protected, or private.
Maybe it's my C++ heritage.
Opinions expressed above are not necessarily my employer's.
James M. Stern stern at itgssi.com (213) 270-7955
ITG Software Solutions, Inc.
Culver City, CA 90230
More information about the Python-list