initializing mutable class attributes
David Bolen
db3l at fitlinxx.com
Wed Sep 1 19:54:06 EDT 2004
"Dan Perl" <dperl at rogers.com> writes:
(...)
> Very good point. I would usually assume that you should initialize the
> superclass's attributes first, and then the subclass's. But that may not
> always be the intent and I may just be influenced by my background in C++
> and Java. (...)
I do find it reasonably common (particularly in GUI applications when
I'm subclassing standard GUI objects) to have a subclass that massages
the constructor inputs slightly (perhaps adding different defaults, or
filtering the arguments) before passing them on to the superclass.
In C++ you can sometimes manage this as long as the manipulation is
simple exclusion or addition that can be performed in the
initialization code prior to the start of the subclass constructor,
but that's very limited (and otherwise can end up forcing you into the
2-phase construction model). So I find Python's freedom of
controlling exactly when the superclass is initialized with complete
control over its arguments very liberating.
-- David
More information about the Python-list
mailing list