initializeInstance
initializeInstance(g_instance[u_?initArg1value1] [u_?initArg2value2] ... ) =>t
Description
Initializes the newly created instance of a class. The initializeInstance is a generic function which is called by the makeInstance function. Methods can be defined for a particular class to allow complex initialization to be performed on the object.
Any slot initialized with an @initarg is initialized before initializeInstance is called. The @initform values are used by the root primary method. So, if a primary method is defined, you should remember to callNextMethod() within that method to ensure that any @initforms are used. The usual practice is to perform any additional initialization in an @after method as all standard initialization has been performed by the time it is called. This @after method can then take additional keyword arguments, or initialize a slot based on the values of other slots.
Arguments
|
A symbol denoting an instance. The instance must be created using |
|
|
|
|
Value Returned
Examples
defclass(A ()
(
(x @initarg x @initform 1)
(y @initarg y @initform 2)
(product)
)
)
defmethod( initializeInstance @after ((obj A) @key product @rest args)
if(product then
obj->product = product
else
obj->product = obj->x * obj->y
)
printf("initializeInstance : A : was called with args - obj == '%L'
product == '%L' rest == '%L'\n" obj product args)
printf(" object initialized to: %L\n" obj->??)
)
makeInstance('A)
initializeInstance : A : was called with args - obj == 'stdobj@0x2d61020' product == 'nil' rest == 'nil'
object initialized to: (x 1 y 2 product 2)
=> stdobj@0x2d61020
makeInstance('A ?x 5 ?y 10)
initializeInstance : A : was called with args - obj == 'stdobj@0x2d61038' product == 'nil' rest == '(?x 5 ?y 10)'
object initialized to: (x 5 y 10 product 50)
=> stdobj@0x2d61038
makeInstance('A ?product 30)
initializeInstance : A : was called with args - obj == 'stdobj@0x2d61050' product == '30' rest == 'nil'
object initialized to: (x 1 y 2 product 30)
=> stdobj@0x2d61050
Related Topics
Return to top