[Tutor] An OO question as relates to Python.

Magnus Lycka magnus@thinkware.se
Mon Oct 21 19:07:01 2002


At 17:29 2002-10-21 -0400, andy surany wrote:
>I re-read the OOP section of the tutor. I guess that what I want to do is
>inherit the attributes of the ScrolledList class to the WINMENU class. Am I
>anywhere near the mark?

Inheritance means "is-a". An employee is a person, so it might
be reasonable that an Emplyee class inherits from a Person class.
WINMENU is a kind of Frame I guess, and thus inherits from Frame.
But it IS NOT a scrolled list, is it? I think it HAS a scrolled
list. Has implies composition, not inheritance. Your frame class
inheriting "ScrolledList" sounds a bit like Employee inheriting
a Salary class. An employee is definitely not a kind of salary.

>But ScrolledList is not defined at the point WINMENU
>is accessed (class WINMENU(Frame,ScrolledList) yields "ScrolledList not
>defined"), as follows:

That could be fixed by changing places, but it's not
what you want unless I'm confused here.

I think I sent a solution to this to you in a previous
email? (Maybe you didn't see my changes in your code?)

In your WINMENU class, I think you need an attribute (also
called a member variable) that points out the ScrolledList.
"self.myScrolledList = ScrolledList(...)" This is set when
you create your scrolled list.

When you populate the list, you simply do
self.myScrolledList.populate_list(options)

>I'm getting dizzy from going around in circles.............

Well, others pay good money for such attractions
and you get it for free! :) No hangover either,
I hope...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se