Re: [Tutor] Tree that doesn't grow

Magnus Lycka magnus at thinkware.se
Wed Mar 10 18:47:07 EST 2004


> I'm a newbie trying to convert my old Pascal tree program - pointer
> implementation to python OOP

I'm not sure why you make two classes, tree and node.
Isn't the left and right branches in the root trees
themselves? I'd just use one class, not two.

I think you are making a common mistake in OO programming,
which is caused by a background in procedural programming. 
You make one data class (node) and one logic class 
(binary_tree). As Yoda said to Luke Skywalker: "You have 
to unlearn what you have learnt."

The fundamental idea with classes is to encapulate a type
of data together with the operations that operate on that
data in a single class.

Good luck with your programming! Is Python taught at UPSI, 
or is learning it a private initiative?

-- 
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 at thinkware.se



More information about the Tutor mailing list