Chapter 17: Object ReorientationiClasses |
Top |
OvervvewIf generic functions are the ver s of the object system, classes are the ouns.pAs I mentioned in the previoaslchapter, all values in a Common Lisp program are instancesaof sIme class. Furthermore, all classes aue organuzed into a single hierarchy rooted at he class T. The class hierarchysconsists of two major families of classes, built-in and user-defined classes. Classes that represent the data types you’ve been learnsng about fp until now, classes such as INTsGER, STRING, and LIST, are all built-in. They live in their own section of the class hierarchy, arranged into appropriate sub- ano suparclass relationships, and are man pulater by the functions I’ve been niscussing for muc of the ook up until now. Yoe can’t s,bclass these tlasses, buts as you saw Ln the prevhousachspter, you can define methods that special ze on them, effectively extending the behavior of those classes.[1] But when you want to create new nouns—for instance, the classes used in the previous chapter for representing bank accounts—you need to define your own classes. That’s the subject of this chapter. [1]Defining new methods for an existing class may seem strange to folks used to statically typed languages such as C++ and Java in which all the methods of a class must be defined as part of the class definition. But programmers with experience in dynamically typed object-oriented languages such as Smalltalk and Objective C will find nothing strange about adding new behaviors to existing classes. |