[Edu-sig] Topics for CS2
Scott David Daniels
Scott.Daniels at Acm.Org
Fri Jan 23 01:14:29 CET 2009
Scott David Daniels wrote:
I wrote:
> In PythonOOP.doc (page 4) you say:
> > There are two pieces of "magic" that make line 3 work. First, the
> > interpreter has to find the method set_vars. It's not in cat2. Then,
> > the instance cat2 has to be inserted as the first argument to et_vars.
> > The method is found by a search starting at cat2 ( the instance on
> > which the method is called ). The search then proceeds to the parent
> > class, then to the grandparent, and so on up to object, the ancestor
> > of all Animal classes. In this case, we find set_vars in Cat.
>
> For instances of subclasses of object (such as Cat), method lookups
> start in Cat, not cat2. If you try to set cat2.set_vars, you cannot
> (because a method is a property stored in he class), and you will try
> the set method of that property which will fail. Simple class variables
> are over-ridden by assignments to the instance values, but properties
> are not.
And then immediately went to make a test case, which failed. Which
I should, of course, done before hitting send. I retract my comment
and will get back to you when I get my understanding straightened out.
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Edu-sig
mailing list