Lisp - CLOS



CLOS, a shorthand for Common LISP Object System, is a versatile object oriented programming system which is an integral part of Common LISP standard. In this chapter, we're discussing key features of CLOS in details.

Features of CLOS

Multiple Inheritance

LISP, unlike many other object oriented languages, supports multiple inheritance. CLOS allows a class to inherits properties from multiple super classes. We can create complex class hiearchies using this feature.

Generic Functions and Multimethods

A generic function can work on one of more arguments. Multimethods concept allows to have different behavior of a generic function based on the arguments passed. It gives a generic function high flexibility and more expressiveness.

Dynamic Object System

CLOS is very dynamic in the sense that we can perform operations on class definition at runtime. We can even change class of an object at runtime. This feature marks the high flexibility of the language.

MOP, Metaobject Protocol

MOP provides a standard interface to customize and extend CLOS behavior. Advanced users can customize objects as per their needs.

Generic Functions vs Classes

In object oriented programming, a class contains the functions to act on the objects but generic functions are not part of the class definition. This features makes LISP, a more modular language.

Advantages of CLOS

Multimethod support

Ability to dispatch based on multiple arguments is a unique feature of CLOS. Developers can write more natural and expressive code using multimethods.

Dynamic by Nature

LISP is very dynamic. Object types are determined at runtime. This feature gives LISP, a high flexibility as compared to statically typed languages.

Method Combination Capability

CLOS provides capability to combine results of multiple methods called during inheritance providing a fine grain control over object behavior.

Conclusion

CLOS is a very flexible and powerful object oriented system to build complex and dynamic applications. Its features like multiple inheritance, multimethods, Metaobject protocols gives LISP a unique edge over other traditional object oriented languages.

Advertisements