class methods vs. functions

Jacek Generowicz jacek.generowicz at cern.ch
Thu Jul 15 08:10:06 EDT 2004


Egbert Bouwman <egbert.list at hccnet.nl> writes:

> but my limited studies of object oriented programming taught me that
> from outside an object you should not use its data-attributes directly.
> Rather you should send the object messages,

Message-passing, while being the most common style of OO, is not the
only style of OO.

You should use the object's interface. This may or may not be
implemented via messages.

> ie use methods of this object.  So z.modules() seems to be the
> better idea, and modules(z) the worse one.

How do you know (without looking at the implementation of
"modules") that "modules(z)" is not "using a method" ?

This is a rhetorical question, which probably needs a bit of
comment. By "method" I don't necessarily mean "Python class or
instance method". You might like to think about "add(a,b)".

> I suppose that this means that you should treat each name foo of a 
> data-attribute as if it was called __foo.

Why treat it as private, if it isn't marked as private? If it isn't
marked as private, then it's part of the interface. If it's part of
the interface, then it is intended for use by clients. If it's
intended for use by clients, then use it.


> my limited studies of object oriented programming taught me

Be careful not to let Java or C++ (or anyone strongly influenced by
them) to shape your understanding of object oriented programming. You
would be doing yourself a disservice.



More information about the Python-list mailing list