Examples of classes with multiple superclasses
happy-kid has a method for #'say but bored-kid doesn't:
? (defmethod say ((child happy-kid) sentence)
(declare (ignore sentence))
(princ "This primary method comes from happy-kid.")
(terpri))
#<Method SAY (HAPPY-KID T)>When CLOS looks for a method, it examines a class before its direct superclasses and a direct superclass before all other direct superclasses specified to its right in the list of the class's parents. Remember, if two of the direct superclasses of a class have a superclass in common, then the order is
1. all of the elements of the first superclass except the class in common
2. all of the elements of the second superclass except the class in common
3. the class in common (followed by its superclasses)
Within those constraints, the local ordering of the class precedence list is determined by taking all the elements of the class and doing a topological sort on them.
Here, bored-kid and happy-kid have a superclass in common, fourth-grader, so bored-kid and happy-kid both affect the behavior of bored-kid-with-pet before fourth-grader does:
? (say bad-max "I hate homework.")
This primary method comes from happy-kid.
NIL
Generated with Harlequin WebMaker