On Tue, Oct 27, 2009 at 12:49 PM, Alan Gauld <alan.ga...@btinternet.com>wrote:
> > "Wayne" <sri...@gmail.com> wrote > >> My favorite example (and the easiest to understand) deals with shapes: >> >> class Shape: >> def __init__(self): >> self.sides = 0 >> self.area = 0 >> >> class Triangle(Shape): >> Shape.__init__(self) >> def __init__(self, base=0, height=0): >> self.sides = 3 >> self.area = base/2*height >> > > Shouldn't the Shape.__init__() call be inside the constructor? > Or is there some deep subtle thing going on here that I'm missing? > > Also how does subclassing Shape add any value here since we just create > local instance vars for sides and area anyway > if they don't already exist? > > Or is this a case of simplifying an example one step too far? > > Confusedly, > > Probably, to all of the above it's applicable to - I've (1) been coding in C++ all morning, (2) was kinda in a hurry, and (3) haven't seen the *actual* example I saw in my CS class for at least a year - it was just the concept of using subclasses that stayed with me. There's probably a wealth of better information out there for the curious individual, and I probably should have just grabbed a link. I'm presuming if you were really doing something like that, the Shape class would take more arguments for instantiation, as well as do some other more useful things. Doh! -Wayne
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor