On August 2, 2020 9:25:32 AM PDT, tbrunz <wild.id...@gmail.com> wrote:
>Shouldn't this code
>
>> So if you implement a #newWhite method in the "class side" of Dog, it
>> would be something like this. 
>> 
>> Dog class>>newWhite
>>   "Returns a new white instance of receiver."
>>   ^self new color: Color white
>
>be this instead?
>
>> Dog class>>newWhite
>>   "Returns a new white instance of receiver."
>>   ^self new 
>>     color: Color white;
>>     yourself
>
>in order to return the new Dog instance?  Otherwise it will return the
>Dog
>class itself (not what you expected?

No. It cannot answer the class. It will answer the result of the last message 
send. That could be the new instance OR the result of sending #white to Color.

This latter point is the reason why people generally like to include the 
#yourself message in the cascade.


>
>-t
>
>
>
>--
>Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply via email to