New to OO concepts - re-usability
Dave Harris
brangdon at cix.co.uk
Sat Feb 24 01:09:00 EST 2001
lopemanc at swbell.net (Chris Lopeman) wrote (abridged):
> Actually much of what you have talked about here is simply covered
> under different topics. Mostly it is referred to as polymorphism.
The principle would be something like:
Maximise polymorphism by avoiding gratuitous differences of
syntax/protocol.
This is a bit more than polymorphism itself. I think it is a fairly
subtle and difficult guideline to follow. People get gratuitous
differences without realising it.
One variation is Meyer's "Uniform Reference Principle". For example, in
C++ and Java (and Smalltalk), direct access to an instance variable has
different syntax to a no-argument message send. Thus:
a = b.c; // Variable.
a = b.c(); // Function call.
The function call has spurious brackets. If we can drop them we get more
polymorphism (if only at compile/link time).
Meyer takes this uniformity to fairly extreme lengths in the Eiffel
libraries. For example, the STACK protocol doesn't use the usual push/pop
names, instead it copies the names used by other collection types. It can
be surprising at first but the benefits are apparently worth it.
There are benefits even if there is not likely to be an opportunity for
polymorphism. If, say, both windows and files use open/close terminology,
it is easier for programmers who know one to learn the other.
Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
brangdon at cix.co.uk | And close your eyes with holy dread,
| For he on honey dew hath fed
http://www.bhresearch.co.uk/ | And drunk the milk of Paradise."
More information about the Python-list
mailing list