The use of inheritance can greatly speed up software development and increase reliability
because new software does not need to be created from scratch each time a new program is
made. OOP makes it easy to utilize reusable code. OOP programmers often make use of
object libraries consisting of hundreds or thousands of objects. These objects can be used or
modified as desired in a new program. In addition to public domain object libraries, a number of
companies market commercial object libraries. Although the concept of reusable software
components has been around since the early days of FORTRAN subroutine libraries in the
1960s, the concept has never before been so successfully used for general software development.
In order to define a class, you must specify one or more parent classes or superclasses of
the class to be defined. As an analogy to superclasses, every person has parents; people do not
spontaneously come into existence (although sometimes you may wonder if certain people really
had parents.) The opposite of a superclass is a child class or subclass.
This determines the inheritance of the new class. A subclass inherits attributes from one or
more superclasses. The term attribute in COOL refers to the properties of an object, which are
named slots that describe it. For example, an object to represent a person might have slots for
name, age, address, and so forth.
An instance is an object that has values for the slots such as John Smith, 28, 1000 Main St.,
Clear Lake City, TX. Lower-level classes automatically inherit their slots from higher-level
classes, unless the slots are explicitly blocked. New slots are defined in addition to the inherited
slots to set all the attributes that describe the class.
An object’s behavior is defined by its message-handlers, or handlers for short. A
message-handler for an object responds to messages and performs the required actions. For
example, sending the message
(send [John_Smith] print)
would cause the appropriate message-handler to print the values of the slots of the instance
John_Smith. Instances are generally specified within brackets, [ ]. A message begins with the
send function, followed by the instance name, message name, and any required arguments. For
example, in the case of the print message, there are no arguments. An object in CLIPS is an
instance of a class.
The encapsulation of slots and handlers inside an object is another of the five generally
accepted features of an OOP. The term encapsulated means that a class is defined in terms of its
slots and handlers. Although an object of a class may inherit slots and handlers from its
superclasses, with a few exceptions discussed later, the object’s slot values cannot be altered or examined
without sending a message to the object.