So, with this mechanism in place we can actually solve a nice problem: Slot initialisation.
on #initialize, we want to hand the new object to each slot to give it a change to initialize it.
Now adding
self allSlots do: [ :slot | slot initialize: anObject ]
to #initialize and doing that for all object is not good as this would slot down all #initialize calls.
We might want to pay that later when if we happen to use it a lot, but now now.
now implements it this way:
1) Slots that want #initialize: the be called on allocation need to implement #wantsInitalization
2) Then magically we add #initialize if needed and, if needed, add
self class initializeSlots: self.
to it.
(this for now just uses text manipulation��� later this will be a nice example for a concept that
we need to reify as part of the MOP: ���I want to hook into object initialization���).
Playing with it
���������������������
(I need to add a tests���)
InstanceVariableSlot subclass: #InitSlot
slots: { }
classVariables: { }
category: ���PlayGround'
initialize: anObject
self write: 5 to: anObject.
wantsInitalization
Now create a class:
Object subclass: #MyCClass
slots: { #ttt => InitSlot }
classVariables: { }
category: ���PlayGround'
MyCClass new ==> ttt is initialised with 5.
For what is this useful?
���������������������������������
1) e.g. the virtual slot that hold the dictionary for all PropertySlots needs to be initialised with an empty Dict
2) We can start to experiment with Slots that specify a value in the definition
3) ���.
Marcus