| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (7 out of 19)

Completing Class Definitions

This section describes:

Subsequent sections describe attributes and techniques whose applicability depends on the type of subclass being defined.

Specifying the Item Configuration

The Item-configuration attribute determines which configurations are in effect for this class. These configurations apply only to the definition itself, not to instances of the class that it defines. Instance configurations are described under Specifying Instance Configurations. For a description of configuration clauses, see Chapter 7, Configurations.

Providing a Class Name

Use the Class-name attribute to specify the name of the class. You can use any symbol that is not already in use. You cannot use a G2 reserved word, or any symbol that denotes a G2 data type. Once specified, the class name appears below the definitions's icon:


The class naming convention in G2 is to use hyphens to separate words in a class name. You can use another allowable G2 character, such as an underscore (_), if you wish.


Note: All class names must be unique within your KB. A class name cannot conflict with another class name even if the definition is of a different type. For instance, you cannot create a CLASS-DEFINITION and an OBJECT-DEFINITION with the same class name.

You must complete both the Class-name and Direct-superior-classes attributes of your definition before G2 considers the definition complete and adds it to the class hierarchy and the menu structure. Until you complete both of those attributes, a definition displays INCOMPLETE in its Notes attribute, as shown in the partial definition that follows:


Specifying the Superior Class(es)

The Direct-superior-classes attribute determines the name of one or more direct superior classes for the new class.

Clicking on any foundation-class in the Text Editor displays a list of all system-defined and user-defined classes (other than mixins) that can be inherited.

Entering Direct Superior Classes

Providing one or more extensible direct superior classes (along with a valid class name) adds the new class to the class hierarchy. When a class exists within the class hierarchy, it inherits attributes from all of its superior classes. Note that you cannot:

A class exists in a KB when it has a unique name and a set of acceptable existing direct superior classes. These prerequisites make it possible to determine the inheritance of the new class, add it to the class hierarchy, and instantiate the class.

If you are creating a class with multiple inheritance (more than one direct superior class), the name of the direct superior class you enter first is significant. The first class in the list is the primary direct superior class. All other direct superior classes are secondary superior classes.

Some restrictions on multiple inheritance must be observed, as described under Illegal Patterns of Multiple Inheritance.

Specifying Direct Superiors Before Creating Their Definitions

You can enter the names of direct superior classes before you have defined them. Specifying a definition with one or more direct superior classes that are not defined, however, does not add the new class to the hierarchy. It merely provides a means for you to create definitions prior to creating all of the required direct superior classes.

A class that does not exist may have potential subclasses, but it cannot have instances. The potential subclasses come into existence simultaneously as soon as you define the missing direct superior class.

When you specify a nonexistent class as a direct superior, the Notes attribute of the class that names the missing superior includes an INCOMPLETE message such as:


Using Mixin Classes

You can use some classes, called mixin classes, with one or more other direct superior classes to add specific properties to a subclass. To use a mixin class, define a class whose Direct-superior-classes attribute includes one or more of the following mixins:

GFI is a superseded capability. For further information see Appendix F, Superseded Practices.

GSI-MESSAGE-SERVICE and UNIQUE-IDENTIFICATION can be mixed in with any class. The other mixins shown can be used only with subclasses of VARIABLE. Mixin classes add the following system-defined attributes to a subclass:

This mixin class... Provides this attribute (s) to your subclass...
GFI-DATA-SERVICE
GFI-input-interface-object attribute. GFI is a superseded capability. For further information see Appendix F, Superseded Practices.
GSI-DATA-SERVICE
GSI-interface-name attribute
GSI-variable-status attribute
Both attributes are described in Chapter 52, G2 Gateway.
GSI-MESSAGE-SERVICE
Gsi-interface-name attribute This attribute is described in Chapter 52, G2 Gateway.
G2-TO-G2-DATA-SERVICE
G2-to-g2-interface-name attribute
Remote-g2-expression attribute
Both attributes are described in Chapter 51, G2 to G2 Interface.
G2-METER-DATA-SERVICE
G2-meter-name attribute This attribute is described in Chapter 44, G2-Meters.
UNIQUE-IDENTIFICATION
UUID This attribute is described in Universal Unique Identifiers.

Specifying Instance Configurations

The Instance-configuration attribute specifies the configuration statements for all instances or subclasses of a definition. These configurations apply only to instances of the defined class, not to the definition itself. Definition configurations are described under Specifying the Item Configuration. For a description of configuration clauses, see Chapter 7, Configurations.

For instance, you may want to configure all instances of a class so that they do not include the Delete menu option. To do this, you could enter the instance configuration as shown here in a partial definition:


Determining the Class Inheritance Path

The Class-inheritance-path attribute specifies the inheritance path from the class you are defining to ITEM. For details, see Class-inheritance-path Attribute and Multiple Inheritance and Class Inheritance Paths.

G2 completes this attribute as soon as you enter one or more direct superior classes and close the edit for the Direct-superior-classes attribute. You cannot edit the value of the Class-inheritance-path attribute.

For G2 to complete the Class-inheritance-path attribute, the direct superior classes you specify must already exist and the inheritance you specify must be valid.

Determining the Initializable System Attributes

The Initializable-system-attributes attribute lists the names of all in initializable attributes that the class definition inherits from the system-defined class(es) in its list of direct superiors. This display is read-only, and appears as soon as you specify one or more legal direct superiors as the value of a class definition's Direct-superior-classes attribute. The default value is none.

For example, the next figure shows the system-defined attributes that you can initialize for a PROCEDURE subclass:


Techniques for providing default values for initializable system attributes are described under Specifying Default Values for Inherited Attributes.

Determining the Inherited User-Defined Attributes

The Inherited-attributes attribute lists the user-defined attributes that the class inherits from its superior classes. This display is read-only, and appears as soon as you specify one or more legal direct superiors as the value of a definition's Direct-superior-classes attribute. The default value is none.

Inherited user-defined attributes appear in the order of the class hierarchy of the class you are defining. Techniques for providing default values for such attributes appear under Specifying Default Values for Inherited Attributes.

Defining and Initializing Class-Specific Attributes

The Class-specific-attributes attribute defines all user-defined attributes that are specific to the class you are creating. The value of an attribute can be a value or an item. The default value of this attribute is none.

You can specify simple attributes (an attribute name without a type or value). Simple attributes have a value of none when they appear in instances and can contain a value of any G2 type when you complete them.

You can optionally specify user-defined attributes to be of a G2 type, with or without a default value, or to be an instance of an object. When an attribute is an instance of an object, G2 creates two items whenever you instantiate the class, one for the class instance, and another for the attribute value. An object created as the value of an attribute does not have an iconic representation and does not appear on a workspace.

When specifying user-defined attributes, you can declare the attribute to be untyped or typed, and to have a default value explicitly specified or provided automatically by G2. For information on G2 types, see Chapter 9, Values and Types.

To specify that the attribute has ... Enter a statement like this...
No type or default value
temp;
weight;
ranch-type

No type and a specified default value
temp initially is 98.6;
weight initially is given by a float-variable;
emergency-code has values red-alert, blue-alert, or green-alert

A type with a specified default value.
temp is a float, initially is 98.6;
weight is given by a quantitative-variable, initially is given by a float-variable

A type with a default value provided automatically by G2.
temp is a float;
weight is given by a float-variable;
ranch-type is an instance of a house

After you enter an attribute name, the editor prompts you to specify the attribute in one of several ways:

You can optionally follow each of these choices with the with an index clause. The next sections describe each kind of attribute expression.

Defining an Untyped Attribute with No Default Value

Specify an attribute that has no predefined properties except its name by entering the name. For example:

Defining an Untyped Attribute with a Default Value

Specify an attribute that has no type with a default value by using the initially is phrase. For example:

You can follow the initially is phrase with:

Defining a Typed Attribute with a Specified Default Value

Specify an attribute as a particular type with a default value using the is a and initially is phrases. For example:

Defining a Typed Attribute with a Default Value Provided by G2

Specify an attribute to have a particular type by using the is a phrase. For example:

The type can be: item-or-value, symbol, value, truth-value, quantity, integer, float, text, structure, or sequence.

Specifying an attribute with a specific type constrains the attribute value to be of that type when:

If you declare an attribute as a type but do not give it a default value, G2 provides one automatically when you complete the edit, by adding an initially is phrase such as this:

The default values that G2 provides for each type are:

Attribute type Default value
float
0.0
integer
0
item-or-value
0.0
quantity
0.0
sequence
sequence ( )
structure
structure ( )
symbol
G2
text
""
truth-value
true
value
0.0

Defining an Attribute as an Object Instance

You can specify an attribute whose value is an instance of any object class, including a variable or parameter class, by using the is an instance of phrase:

For example:

If you do not provide a default value, G2 provides one automatically by adding an initially is an instance of phrase that instantiates the specified class:

You can give an initially is an instance of phrase that specifies the default value as a more specific class than the type of the attribute requires:

Instantiating a class that has an attribute whose type is an object class actually instantiates two classes: the class itself, and the class specified as the default value of the attribute. The instance of the latter class:

The next example shows a SPECIAL-PRESSURE object, whose Inner-pressure attribute is given by a float-variable. The variable is shown in the object attribute table as asterisks (****), because it has no value. Clicking in the value of that attribute and choosing subtable displays the attribute table of the variable.

You can specify the value of an attribute to be an instance of the class that defines the attribute. To prevent an infinite regress, G2 limits the depth to 20 items when you instantiate such a class. The value of the attribute in the most deeply nested instance is none.


Defining an Attribute for Implied Symbolic Reference

Specify an attribute that is to be used with an implied symbolic reference as follows:

Use attributes defined with the has values phrase in expressions that imply an attribute. For example, using the example above for the PC class, once instances of the class exist, you could use an implied attribute reference such as:

to reason about the value of the pc-operating-system attribute. The statement specifies the class and a value, rather than an attribute name. From this statement, G2 infers that the expression refers to the pc-operating-system attribute, because it is the only attribute that can have the specified value.

Defining an Indexed Attribute

Specify an attribute with an index by using the with an index clause:

Use indexed attributes when you need an efficient way to locate a particular attribute value among many objects. G2 provides various expressions to use with indexed attributes.

While the Text Editor does not prevent you from entering the with an index clause after any attribute, you can index only attributes that are:

For information about using and referring to indexed attributes, see Using Indexed Attributes.

Specifying Default Values for Inherited Attributes

The Attribute-initializations attribute lets you set default values for all user-defined attributes and many system-defined attributes. System-defined attributes are part of each class in the hierarchy. You cannot change or delete them. Some system-defined attributes, like Notes and Names, appear in every G2 item.

Overriding Default Values of Inherited User-Defined Attributes

The Inherited-attributes attribute lists the user-defined attributes that a class inherits from its superior classes. Each of these already has an inherited default value. Using the Attribute-initialization attribute, you can override the inherited default value of any inherited user-defined attribute.

The grammar for such initializations differs from the grammar for overriding the default value of a system-defined attribute, which is described under Specifying Default Values of Initializable System-Defined Attributes.

To specify a default value for an inherited user-defined attribute:

You can select one or more of the applicable phrases shown in the next figure to specify Attribute-initializations. Separate consecutive initializations with a semicolon (;).

If user-defined attribute is... Then you can...
Without a type, such as:
Supply a new default value of your choice, optionally followed by a unit of measure, such as:
With a type, such as:
Supply a new default value of the same type, such as: If you provide a value of a different type than the inherited attribute, G2 lets you complete the edit. However, a message displays in the Notes attribute, indicating that the value will not take effect.
Given by a variable or a parameter, such as:
Supply a new default value only if the value is a subclass of the inherited class of the attribute, such as (for the example on the left):
Initially an instance of an object subclass, such as:
Change the instance of one object to any other allowable object, such as:

As part of the capability to create and complete definitions in bottom-up order, G2 allows you to specify user-defined attribute initializations for currently non-existent inherited attributes. When such an initialization exists, the definition's Notes attribute displays a message such as the following:


Specifying Default Values of Initializable System-Defined Attributes

The Initializable-system-attributes attribute lists the names of all initializable attributes that the definition inherits from the system-defined class(es) in its list of direct superiors. Each of these already has an inherited default value. Using the Attribute-initialization attribute, you can override the default value of any initializable system-defined attribute.

For example, you can specify the system-defined attributes array-length and the element-type for an array definition in Attribute-initializations. These two attributes appear on the attribute table of an array.

The grammar for such initializations differs from the grammar for overriding the default value of a user-defined attribute, which is described under Overriding Default Values of Inherited User-Defined Attributes.

To specify a default value for an initializable system-defined attribute:

Separate adjacent initializations with a semicolon (;). The following definition for a subclass of procedure specifies default values for the initializable system attributes tracing-and-breakpoints and default-procedure-priority:


Initializations of inherited user-defined attributes and initializable system-defined attributes can be intermixed as desired. Separate the adjacent initializations with a semicolon (;). Be careful not to confuse the different grammars of the two types of initialization.

For information on the initializable system attributes of any class, see the documentation in this manual for that class. For additional information on the initializable system attributes of:

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (7 out of 19)

Copyright © 1997 Gensym Corporation, Inc.