[Grace-core] Inheritance and object initialisation

Andrew P. Black black at cs.pdx.edu
Fri Jul 27 21:22:49 PDT 2012


This is the mail that I never sent.  But you have worked it out now without me.

> Sorry, there was a critical bug in my code.  Where I wrote
> 
> 	inherits initializingClass.new
> 
> I mean, of course, 
> 
> 		inherits initializingClass
> 
> That was the whole point!   My error in not running any tests :-(
> 
> On 25 Jul 2012, at 13:07, Kim Bruce wrote:
> 
>> I'm afraid I don't understand how initializedNew is invoked (you never seem to use it in your example). 
> 
> It's invoked by the client who wants to create an initialize a new object.  
> 
> Here is my version of your code.  It prints "new object / new initialize".  If you want the code to do old initialize too, then the object (not the class) needs to inherit from an object with an initialize method, and the overriding initialize needs to say "super.initialize".
> 
> (This is in /NewOOL/GUnit/GUnit project/Initialize.grace)
> 
>> def initializingClass = object {
>>     method initializedNew {
>>            self.new.initialize
>>     }
>>     method new {print "superclass new method"}        // I assume that "is abstract" means that it can be overridden without an overrides annotation.
>> }
>> 
>> def aCanvas = object {
>>     inherits initializingClass
>>     method new is override { 
>>         object { 
>>             print "new object"
>>             method initialize {print "new initialize"}
>>         }
>>     }
>> }
>> 
>> aCanvas.initializedNew
>> 
> 


More information about the Grace-core mailing list