[Next] [Previous] [Up] [Top] [Contents] [Index]

Methods

Customizing initialization with initialize-instance

Creating instances is not only a matter of associating values with slots; other initialization must often be performed. You specify what needs to be done by specializing the generic function initialize-instance. A method on initialize-instance for fourth-grader might look like the following:

(defmethod initialize-instance ((child fourth-grader)
                                &rest initargs)
   (add-to-class-list child)
   (check-vaccinations child)
   (check-special-programs child))

When an instance of fourth-grader is created, make-instance calls initialize-instance, which calls the functions add-to-class-list and so on. These functions run their methods for fourth-grader. The functions that make-instance calls do not need to be generic functions and, if they are, do not need to have methods specifically for fourth-grader; they might have methods for one of the class's superclasses.


Gettmg Started with MCL - 19 OCT 1996
[Next] [Previous] [Up] [Top] [Contents] [Index]

Generated with Harlequin WebMaker