Classes and Class Hierarchy
Overview of the G2 Class Hierarchy
This section briefly summarizes the G2 class hierarchy, and introduces the terminology G2 uses to describe it. The rest of this chapter builds on and expands the information in this section.
Items and Classes
To represent knowledge in a KB, you need abstractions that represent the things that the KB models. G2 calls these abstractions items. Many object systems call such abstractions objects, but in G2 terminology an object is a particular kind of item, as described later in this chapter.
To perform automated reasoning about items, we need a way to categorize them. G2 calls categories of item classes. Classes facilitate automated reasoning just as the categories from which they derive facilitate ordinary thought.
G2 implements every class as a set of properties called attributes that are common to all members of the class. Examples: name, size, weight, status, color, cost. G2 implements every item as an instance of some class. Creating an instance is called instantiation. Every instance can define a particular value for each attribute characteristic of its class. Examples: Tank-1, Large, 100 pounds, Repaired, Green, $49.95.
For information about:
Ordinary thinking requires understanding the behavior as well as the properties of real things. Similarly, automated reasoning requires procedures that define what items do and how they change. G2 calls such procedures methods. Examples: clean, fill, pressurize, sample, empty. For complete information about methods, see Chapter 22, Methods.
This chapter describes these three uses, and provides pointers to additional information in other chapters.
Just as things can have common properties, allowing them to be grouped into categories, so categories can have common properties, allowing them to be grouped into supercategories. These in turn can be grouped, and so on until the most general possible category is reached.
The grouping of categories into more encompassing categories is called generalization. The inverse process, in which categories are subdivided into increasingly specific subcategories, is called specialization or refinement. These terms are common in object-oriented programming generally; they are not specific to G2.
G2 uses common properties to organize classes into a class hierarchy. The highest class is called the root class. It has only attributes and methods common to all classes, and is the only class that has no parents.
The root class has subclasses, each of which inherits those attributes and methods, and defines additional attributes and/or methods specific to its purpose. These subclasses can in turn have lower-level subclasses, with yet more specific attributes and/or methods, and so on to any depth.
The defining of increasingly specific subclasses is called subclassing. Attributes and methods inherited by a subclass from a more general class are called inherited attributes and inherited methods. Additional attributes and methods defined by a subclass are called class-specific attributes and class-specific methods.
When every subclass inherits from only one class, the result is a tree of classes. G2 calls such inheritance single inheritance, and describes trees of classes using the usual terminology for hierarchies: root, parent, child, sibling, and leaf. The classes from which a class inherits, directly or indirectly, are its superior classes. A class's parent in the hierarchy is its direct superior class.
Single inheritance can represent most knowledge, but not all. For example, mules, the offspring of horses and donkeys, cannot be represented via single inheritance.
To provide for any possible information structure, G2 allows a subclass to have any number of parents (direct superiors). The subclass then inherits all the attributes and methods of all of its parents. G2 calls such inheritance multiple inheritance. A class structure that includes multiple inheritance is not a tree, but it remains a hierarchy because it has a unique root class and contains no circular structures.
Multiple inheritance entails the possibility of inheriting duplicate or inconsistent attributes and methods. These could introduce ambiguities and conflicts into a subclass's definition. Preventing such problems requires assigning a precedence order to the contributors to a subclass's inheritance, and using it to prevent problems. Establishing such an order is called linearization.
Purpose of Inheritance
G2 uses a class's inheritance in three different ways:
Copyright © 1997 Gensym Corporation, Inc.