class methods vs. functions

Greg Ewing greg at cosc.canterbury.ac.nz
Fri Jul 16 00:49:22 EDT 2004


Egbert Bouwman wrote:
> My impression is that you can hardly call this OOO:
> Object Oriented Orthodoxy. For instance, from the GOF I learned:
> - the object's internal state can not be accessed directly
> - operations are the only way to change an object's internal state

What you're missing is that, in Python, attribute access
*is* an operation, on the same footing as calling a method.
The object can be programmed to respond to it in any
desired way. So, exposing an attribute as part of the
public interface in no way limits the current or future
implementation.

This is in contrast to languages such as C++ and Java,
where attribute access cannot be overridden, so you
are forced to use accessor methods for everything in
order to keep interface and implementation separate.
The rules as you have learned them were designed for
those languages.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list