Previous | Table of Contents | Next |
A computer program uses a model to guide the implementation. When implementing the system, its often convenient to think about the system as objects: entities that have characteristics. Object-oriented programming allows the program to represent as similar in source code entities that differ in details, but are convenient to think about as similar. These entities are known as objects. Objects with the same characteristics are bundled as generic types known as classes. Objects might represent managers, employees, and departments in a business application or might represent events, locks, and windows in a window system.
CLOS makes it easy to model a system using objects. A window system may have many components that conceptually handle the same operations: Window panes and scrollbars both want to support operations such as mouse-in, mouse-out, and mouse-click. The underlying implementation of what a mouse-click does is quite different in a window pane and in a scrollbar, but conceptually, it is a lot simpler to treat them as being the same. CLOS has a rich, flexible, and complete object model.
Like other object systems, CLOS supports separation of implementation from the interface. Objects are known only by their interface, or the set of operations that can be performed on them. Other components of the application use these operations to create and interact with these objects and do not have knowledge of the actual implementation of each underlying object.
The separation of interface from implementation is one of the key benefits of object programming: Objects may be modified, extended, or implemented differently without the rest of the program, which depends only on the interface, needing to be changed. New objects with the same interface may be introduced into the system without the rest of the program needing to be changed.
CLOS makes it easier to design, develop, extend, and maintain a program. The larger the program, the more complex it is, and the more important it is to structure it into modules that minimize the dependencies between them. Use of object-oriented programming in CLOS supports this type of decomposition into separately maintainable and extensible components that interact only using interfaces.
Like the rest of Lisp, CLOS is a completely dynamic language that is runtime extensible without the need for all the source code. In the running application, classes can be redefined or extended, objects can change their class, and methods can be redefined or added. As you shall see later, important applications are built that rely on this feature.
To summarize, using CLOS in Lisp applications adds the following benefits:
In keeping with the Lisp tradition of extensibility and openness, CLOS makes no attempt to enforce modularity or to hide implementation across module boundaries. Instead, it encourages application programmers to use CLOS to design modular and extensible programs.
CLOS programs consist of classes, instances, generic functions, and methods. CLOS programs are put together with inheritance, method combination, and, of course, regular procedural Common Lisp code. Ill introduce these elements in this section and occasionally contrast the terminology and use against a couple other popular object-oriented languages: C++ and Smalltalk.
For a good introductory book on both CLOS and object-oriented programming, see Object-Oriented Programming in Common Lisp (Keene, 1989).
Previous | Table of Contents | Next |