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

Representing Physical and Conceptual Relationships

G2 supports two additional object-oriented techniques that allow you to represent relationships between objects:

Connections and relations are similar in some ways and different in others. This section provides examples of connections and relations, describes how to create and delete connections and relations, and provides some guidelines for choosing one type of data structure over the other.

Examples of Connections

One use of connections is to represent relationships between physical objects, such as:

Another use connections is to represent relationships between conceptual objects in graphical programming and modeling languages, for example:

Examples of Relations

You use relations to represent conceptual connections between either physical or conceptual objects, such as:

Using Connections to Represent Graphical Relationships

Your physical systems are typically connected to each other in various ways, depending on the environment. Robots in an assembly line are connected by roadways, tanks in a chemical plant are connected by pipes, and nodes in a telecommunications environment are connected by wires.

You represent "connected to" relationships in G2 by:

For example, in a manufacturing application, robots might be connected to one another in an assembly line. As the following figure shows, each instance inherits its stubs definition from its class, and you connect object together by connecting their stubs:


Creating and Deleting Connections

To create a connection, you create a class definition and specify stubs of a particular connection class. You can either use the built-in CONNECTION class or create a subclass of connection. You can then create and delete connections interactively or programmatically.

Defining a Connection Class

G2 provides the CONNECTION class from which you can define your own connection class. You can also declare connection stubs for a class by referring to the connection class directly.

One reason for defining your own connection class is to provide a custom cross-section pattern for the connection, which you use to restrict the types of connections that an instance can have.

To create your own connection subclass:

Declaring Connection Stubs for a Class

When you declare default connection stubs for a class, you can specify the:

To declare connection stubs for a class:

For example, this declaration creates an instance of the built-in CONNECTION class at the top of the icon with a diagonal connection style:

Creating and Deleting Connections Between Objects

You can create and delete connections interactively or programmatically.

To create connections between objects:


Note: In general, you should not store information in the attributes of a connection, because connecting stubs can result in lost information. Connecting two stubs actually deletes both stubs and replaces them with a newly created connection. G2 retains only the attributes of one stub during this operation.

To delete connections between objects:

For more information on connections, see the G2 Reference Manual.

Using Relations to Represent Non-Graphical Relationships

During the course of processing, your application might need to establish non-graphical relationships between objects dynamically. These relationships might become a permanent part of your knowledge base, or they might be dynamically deleted during the course of processing. For example, a computer in a network might be temporarily "in communication with" another computer.

You can establish relations between exactly two objects, between one object and many objects, between many objects and one object, or between many objects and many objects. For example, you might establish a relation between a bottle and a bottling station as the bottle moves along an assembly line. A bottle can be "located at" at most one bottling station at a time, whereas a bottling station can "contain" more than one bottle at a time. This concept is called the cardinality of the relation.

You also establish relations between objects that represent physical systems and user interface objects.

You represent "related to" relationships in G2 by:

Creating and Deleting Relations

To create a relation, first you must create a relation definition. Once the relation definition exists, you create and delete relations programmatically.

Creating a Relation Definition

To create a relation definition:

  1. Choose KB Workspace > New Definition > relation.

  2. Specify the Relation-name attribute.

  3. Specify the class of the relation source as the First-class and specify the class of the relation target as the Second-class.

  4. Specify the cardinality of the relation in the Type-of-relation attribute.

    The options are: one-to-one, one-to-many, many-to-one, or many-to-many.

  5. Specify whether the relation also exists between the second class and the first class by specifying the Relation-is-symmetric attribute.

  6. Specify whether the relation survives a G2 reset by specifying the Relation-is-permanent attribute.

Concluding and Breaking Relations Between Items

Once you have defined the relation, you programmatically create and delete relations between instances or classes of objects. You can also replace one relation with another.

To create a relation:

For example:

To delete a relation:

For example:

To replace a relation:

For example:

Detecting Connection and Relation Events

You can use connections and relations to trigger whenever rules. G2 detects these connection and relation events:

For examples of the syntax for these types of events, see Using "Whenever" Rules to Detect Events.

Comparison Between Connections and Relations

This table compares the features of connections and relations:

Connection Relation
Provides a graphical representation of the relationship


Allows control over the direction of flow of data


Allows direct control over cardinality of relationship (one-to-one, one-to-many, many-to-one, or many-to-many)


Supports symmetrical relationships


Allows relationships between instances


Allows relationships between classes


Supports interactive creation and deletion


Supports programmatic creation and deletion


Can be a transient or permanent object in the KB


Triggers "whenever" rules upon creation or deletion


Can indicate specific participatory classes



Note: While connections do not provide direct control over cardinality and participatory classes, you can specify a cross-section pattern for connections and create default stubs for classes, which constrains the items to which another item can be connected.

Guidelines for Using Connections and Relations

These are the general guidelines for choosing between connections and relations.

Use Connections to Create Graphical Relationships

You use connections whenever you want to create a graphical relationship between items that exist on a workspace.

You can customize the cross-section pattern of a connection by creating a subclass of the built-in CONNECTION class.

Use Connections to Provide Configurability

You use connections when you want to provide a way to configure the relationship between objects. Because connections have a graphical representation, you can use them to obtain information from the end user about the relationship. For example, in a graphical language that processes objects, the end user might specify the type of object by configuring the connection between two "tasks," such as in ReThink, a G2 application product for business process reengineering.

Use Connections to Provide Information about Relationships

You use connections when you want to provide feedback to the end user about the relationship between two objects. For example, in a graphical language that passes data, the end user might click on a connection to display information about the data flowing between two "blocks," such as in GDA, a G2 application product for real-time monitoring, diagnostics, and control.

Use Relations to Create Non-Graphical Relationships

You use relations whenever you want to create a non-graphical relationship between items that do not have an icon representation, and, thus, do not reside on a workspace.

Use Relations to Control the Number of Related Items

Sometimes, a single item can be related to only one item at a time, such as a bottle at a station that fills the bottle with a liquid. Other times, a single item can be related to many items, such as a server on a network.

You use relations to control the cardinality of a relation, which determines how many instances of one class can be related to how many instances of another class. If you attempt to create a relationship that violates the cardinality of the relation, G2 disallows the relation. Thus, you can use relations to control the number of items that can be related at any one time.

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

Copyright © 1997 Gensym Corporation, Inc.