[Tutor] Problems with references

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Jun 3 08:02:41 EDT 2004

> >Possibly different schools :-)
> We are... :)
> Now it all makes sense to me, thank you very much. I had no idea
> OOP also worked in that direction.
> 2 small questions if it is ok...
> 1. "self" is that a reference to the class or an instance of the

Depends on the language, but in Python self in a classmethod means
the class, self in an instance method means the runtime instance:

>>> class C:
...   def f(self):
...     self.x = 42
...   f = classmethod(f)
...   def g(self): self.y = 27
>>> C.x
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: class C has no attribute 'x'
>>> C.f()
>>> C.x
>>> c = C()
>>> c.x
>>> c.g()
>>> print c.x, c.y
42 27

> 2. Since that there are different paradigms within the OOP
> which one is the most "correct"? (I know it is a wierd question.)

There is only one paradigm for class attributes and methods, its
just a matter of how well supported it is in different languages.
C++/Java support it partially, Python, Lisp, Java etc support it well.
Delphi supports it slightly beter than C++ but not as well as
etc. Lisp/CLOS probably support the full theoretical OOP model best.

Alan G.

More information about the Tutor mailing list