To represent objects of a similar type, you create instances that are a "type of" a particular class. The individual instances of the class are "analogous to" the other instances of the class.
You represent "type of" relationships and "analogous to" relationships in G2 by:
The following figure illustrates the concepts of classes and instances for the
ROBOT class. The robot class defines the common attribute of its instances, Arm-span, and the common methods of its instances, grasp and turn. Each instance has the same icon but different names and attribute values, and each has the same set of methods:
![]() |
Creating a Class Definition
This section summarizes the major steps in creating a class definition.
To create and specify a class definition:
KB Workspace > New Definition > class-definition > class-definition.
Name and Direct-superior-classes of the class definition to specify the built-in classes from which the class inherits its definition.
Class-specific-attributes of the class definition to specify its characteristics.KB Workspace > New Definition > procedure > method-declaration to create a method declaration for the method.KB Workspace > New Definition > procedure > method to create a method for the class that implements its behaviors.edit icon on the class definition to edit its icon representation.
ITEM class, or you can view the class hierarchy of any subclass of item.
To view the entire G2 class hierarchy:
Use the Inspect facility to show on a workspace the class hierarchy of item.
To create an instance of a class:
Choose create instance from the class definition menu.
or
Use the create action, and, optionally, the make permanent action to create the instance programmatically.
The subclasses of the
OBJECT class from which your user-defined classes can inherit include these categories of classes:
As another example, your application might require a variable that allows communication with an external system through the G2 Gateway. To provide this capability, you would:
FLOAT-VARIABLE
Subclass User-Defined Classes
Once you have created a user-defined class, you can begin to build a class hierarchy by creating new classes that inherit from existing user-defined classes. Typically, your class hierarchy consists of classes that ultimately inherit from the OBJECT or ITEM class.
Subclass Built-in Definition Classes
You might want to create your own subclasses of the G2-WORKSPACE class to provide user-defined workspaces with different colors for different types of knowledge. You might also want to create subclasses of the RULE class to provide user-defined rules with different scan intervals, focal classes, or categories. By subclassing built-in definition classes, you can extend these definitions to provide a custom development environment. ITEM class to create a subclass of these categories of definition classes:
ITEM class. Thus, all objects in G2 are considered items. For consistency with object-oriented terminology, we often refer to G2 items as objects. However, keep in mind that some G2 objects, such as class definitions, methods, procedures, rules, and workspaces, are actually subclasses of the ITEM class and are considered items in G2.
KB Workspace > New Object menu. In general, you should declare private and abstract classes to be non-instantiable, and you should keep them off the New Object menu. If your module provides a palette for the creation of new items, you should also remove from the New Object menu those classes that appear on the palette.
To declare a class as non-instantiable:
Specify the Instantiate attribute in the class definition as no.
To remove a class from the New Object menu:
Specify the Include-in-menus attribute in the class definition as no.
MESSAGE class as the superior class. Aside from the ability of a message to contain text, the two reasons to inherit from message are: