#initialize and MC

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

#initialize and MC

Damien Cassou-3
Hi,

I would like Monticello to initialize all the classes it is loading.
Normally it is done by implementing a #initialize method on the class
side. However, sometimes, it is not called.

How does it work ? What can I do ?


Thank you

--
Damien Cassou


Reply | Threaded
Open this post in threaded view
|

Re: #initialize and MC

Damien Cassou-3
It seems #initialize (on the class side) is called by Monticello only if
implemented in the class directly. Am I right ?

I want the same initialization code to be launched for a class and all
its subclasses. It is possible to do this without copy-pasting ? Maybe
with Traits. Nothing simple ?

It's very strange that #initialize is only called for the implementing
class, I don't understand why.

Bye

--
Damien Cassou


Reply | Threaded
Open this post in threaded view
|

Re: #initialize and MC

Mathieu SUEN
Damien Cassou a écrit :

> It seems #initialize (on the class side) is called by Monticello only if
> implemented in the class directly. Am I right ?
>
> I want the same initialization code to be launched for a class and all
> its subclasses. It is possible to do this without copy-pasting ? Maybe
> with Traits. Nothing simple ?
>
> It's very strange that #initialize is only called for the implementing
> class, I don't understand why.
>
> Bye
>

You can test:

initialize

        super initialize


Reply | Threaded
Open this post in threaded view
|

Re: #initialize and MC

Alejandro F. Reimondo
In reply to this post by Damien Cassou-3
Damien,
Please revise why you need to initialize the class...
It is common the use of instance class variables or globals
 and if this is the case, it is recommended to use accessors
 and deferred initialization.
It is not correct to assume that #initialize will be sent and
 it will success (in case of error, your class will be partially
 "initialized").
If you write deferred initialization, ensure that the setting is
 commited at end of the metod, to give a new chance to
 sucess if an error is triggered when constructing the
 initial object.
cheers,
Ale.


----- Original Message -----
From: "Damien Cassou" <[hidden email]>
To: "The general-purpose Squeak developers list"
<[hidden email]>
Sent: Saturday, September 16, 2006 3:15 PM
Subject: Re: #initialize and MC


> It seems #initialize (on the class side) is called by Monticello only if
> implemented in the class directly. Am I right ?
>
> I want the same initialization code to be launched for a class and all
> its subclasses. It is possible to do this without copy-pasting ? Maybe
> with Traits. Nothing simple ?
>
> It's very strange that #initialize is only called for the implementing
> class, I don't understand why.
>
> Bye
>
> --
> Damien Cassou
>
>


Reply | Threaded
Open this post in threaded view
|

Re: #initialize and MC

Damien Cassou-3
Alejandro F. Reimondo a écrit :
> Damien,
> Please revise why you need to initialize the class...

Each subclass sets a new preference in the preference browser.

Current implementation is in the super class which is abstract:

DPAbstract class>>initialize
   self isAbstract
     ifFalse:
       [Preferences
         addBooleanPreference: self preferenceName
                     category: #'dynamic protocols'
                      default: self defaultPreferenceValue
                  balloonHelp: 'Activates the dymamic protocol ',
                                 self name, '.'].

DPAbstract class>>preferenceName
   ^ self name copyFrom: 3 to: self name size

The preference name is taken from the name of the class without the
first two characters.

Do you have another solution ?


--
Damien Cassou


Reply | Threaded
Open this post in threaded view
|

Re: #initialize and MC

Bert Freudenberg
In reply to this post by Damien Cassou-3

Am 16.09.2006 um 13:49 schrieb Damien Cassou:

> Hi,
>
> I would like Monticello to initialize all the classes it is  
> loading. Normally it is done by implementing a #initialize method  
> on the class side. However, sometimes, it is not called.
>
> How does it work ?

Monticello loading mimics changeset loading. So if you load a package  
for the first time, this is equivalent to a full changeset, and if  
some metaclass implements #initialize, then it will be sent. However,  
if a package was already loaded, Monticello builds a changeset that  
only contains the difference between what is in the image and what is  
loaded, and loads that. Now, if the #initialize method is not  
modified in your new version, it is not in that differential  
changeset, and hence will not be run. To force re-initialization,  
modify #initialize.

- Bert -