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

Specifying Instantiability

Instantiation applies to all user-defined classes except subclasses of connection. Instantiability is controlled by two definition attributes: Instantiate and Include-in-menus. These two attributes are collectively called the instantiation attributes. When you create a new definition, the default value of both instantiation attributes is yes.

To specify that a class is/is not instantiable:

To specify that a class does/does not appear in G2 menus:

Effects of Setting Instantiability Attributes

When you add a class to the class hierarchy, its name always appears in the list of available classes (via the Direct-superior-classes attribute), and in the class hierarchy schematic available through the Inspect facility (show on a workspace the class hierarchy).

Other than that, the accessibility of the class depends on the values of its instantiability attributes. The effects and interaction of these attributes are summarized in this table:

Include-in-menus
yes no
Instantiate yes
The class can be instantiated programmatically and appears in G2 menus, allowing it to be instantiated interactively.
The class can be instantiated programmatically, but does not appear in G2 menus, so it cannot be instantiated interactively.
no
The class cannot be instantiated, but appears in G2 menus where necessary to permit navigation to a subclass that is instantiable and appears in menus.
The class cannot be instantiated and does not appear in any G2 menu. The class may have subclasses that are instantiable and/or appear in menus.

Instantiable Classes That Appear in Menus

Whenever you create a new class, G2 adds the class to the class hierarchy. If the class is instantiable and appears in menus, the G2 menu of the class definition then includes the choice create instance. Choosing create instance instantiates the class.

G2 also adds the class to the G2 menu hierarchy. For instance, an object class appears at some level under kb-workspace > new object, and a subclass of kb-workspace appears at some level under main menu > new workspace.

When a class that is instantiable and appears in menus has a subclass that is also instantiable and appears in menus, the higher-level class appears more than once in the menu hierarchy:

Creating a subclass with more than one direct superior class adds the new subclass to the menu structure of each of the superior classes. For instance, creating a subclass of OBJECT and G2-TO-G2-INTERFACE called G2-TO-G2-OBJECT, adds the G2-TO-G2-OBJECT class to both the new object and the g2 to g2 interface submenus.

Noninstantiable Classes That Appear in Menus

A class that is noninstantiable does not include create instance in its G2 menu, but it appears as a higher-level entry in the menu hierarchy if and only if it is an ancestor of a class that is instantiable and appears in menus. Its appearance at the higher level facilitates navigating the menu hierarchy to the instantiable class.

Classes That Do Not Appear in Menus

Such a class does not include create instance in its G2 menu, and does not appear in the menu hierarchy even if has an instantiable subclass that appears in menus. The instantiable subclass appears in the hierarchy as a subclass of the first of its ancestors that does appear in menus, or perhaps of more than one such ancestor if it has multiple inheritance.

Order of Classes in the G2 Menu Hierarchy

There is no particular order to the way in which G2 adds new classes to menus, nor is the order of display permanent across G2 sessions. User-defined classes may appear on the menus before system-defined classes, or after them, and then appear in a different order after you start a new G2 session.

Uninstantiable Subclasses

In order to be instantiable, a class must inherit at least one instantiable class. When a class is not instantiable because its system inheritance does not include an instantiable class, and the class's Instantiate attribute is yes, G2 ignores the value of the attribute, and includes a Note that states:

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

Copyright © 1997 Gensym Corporation, Inc.