[Newbies] Question about inheritance

stephane ducasse stephane.ducasse at gmail.com
Fri Oct 13 19:57:12 UTC 2006


Hi dennis

two points:

- aClass new returns an instance of that class

- super represents the receiver of the message but the lookup of the  
method in the superclass
of the class that contains the super call. Once the method is found  
it is applied to the original receiver.

So now
Monster class>> new
	
	^ super new initialize


is executed when you do Monster new

what is the receiver of the message new => Monster.

So super new is looked up in the super class of Monster and once  
found applied on
Monster, then point 1 makes that you get back an instance of the  
receiver of the message new.

Stef









On 13 oct. 06, at 15:57, dennis petrocelli wrote:

> Greetings smalltalkers,
>
> I'm a newbie trying to get my head around inheritance.  I'm puzzled  
> by the following example.  It seems to do what I mean, but not what  
> I type ;)  This is a good thing, but I'd get further if I  
> understood the semantics a bit better.
>
> from http://www.cosc.canterbury.ac.nz/wolfgang.kreutzer/cosc205/ 
> smalltalk1.html
>
> Class: Monster
> Superclass: Object
> Category: Sesame Street
> Instance variables: colour tummy
>
> initialization
>
> initialize
>    self colour: #green.
> self tummy: Bag new
>
> "There is only a single class method and no class variables."
>
> creation
> new
>    ^ super new initialize
>
> What I don't understand is this:  Monster new returns an instance  
> of Monster, what you'd want it to. But Monster new executes "^  
> super new" which to my mind should return an instance of Object,  
> not Monster.  Just to confuse myself further, I typed:
>
> Monster superclass new
>
> and got an Object.  It seems to me that "super new" and "superclass  
> new" should do the same thing.
>
> Any points to clarify my confusion would be greatly appreciated.
>
> Thanks,
> Dennis Petrocelli
>
> Do you Yahoo!?
> Everyone is raving about the all-new Yahoo! Mail.
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners



More information about the Beginners mailing list