5 The Class Browser
Note: We recommend that you read your Common Lisp text's description of classes, class objects, methods and generic functions before continuing with this and the following two chapters of this manual. You will not need to use the class browser, inspector or generic function browser until you understand those concepts.
In this example, the basic class is animal
. All other classes in the system are merely refinements of animals, and so are derived from it. The animal
class is split into mammals, birds, and reptiles and so a class is derived from animal
for each of these. We can specify slots which identify particular characteristics, for example, we can use the slot alive
to specify whether or not an animal is alive (Y
or N
), and the slot sex
to specify which sex an animal is (M
or F
).
Enter the definitions below:
CL-USER 1 > (defclass animal () (alive sex)) #<STANDARD-CLASS ANIMAL 00482C64> CL-USER 2 > (defclass mammal (animal) (pregnant)) #<STANDARD-CLASS MAMMAL 00487414> CL-USER 3 > (defclass bird (animal) (flies)) #<STANDARD-CLASS BIRD 0048A20C> CL-USER 4 > (defclass reptile (animal) (scaly)) #<STANDARD-CLASS REPTILE 0048D4F4> CL-USER 5 >This establishes the class hierarchy depicted in Figure 5.2, below:
Figure 5.2 Animal example class hierarchy.
A file called animals.lsp
contains a number of such definitions which you may wish to use whilst learning about classes. This is in the examples directory.
Generated with Harlequin WebMaker