nearest to searches, which are computationally intensive
You represent "connected to" relationships in G2 by:
CONNECTION class or a subclass of connection
![]() |
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.
To create your own connection subclass:
Create a class definition that inherits from the CONNECTION class and specify Attribute-initializations for system-defined attributes, such as Cross-section-pattern.
CONNECTION class
To declare connection stubs for a class:
Edit the Attribute-initializations attribute of the class definition to initialize the Stubs system attribute of the class.
CONNECTION class at the top of the icon with a diagonal connection style:
stubs: a connection located at top 15 with style diagonal
To create connections between objects:
Drag the connection stub from one object into the connection stub of another object or directly into the object itself.
or
Use the create a connection action, and, optionally, the make permanent action to create the connection programmatically.
To delete connections between objects:
Click on the connection between two objects and choose delete.
or
Use the delete a connection action after you have made the connection temporary.
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:
in-communication-with, which specifies which classes can be related to which other classes, and how many classes of each can be related
To create a relation definition:
KB Workspace > New Definition > relation.
Relation-name attribute.
First-class and specify the class of the relation target as the Second-class.
Type-of-relation attribute.
one-to-one, one-to-many, many-to-one, or many-to-many.
Relation-is-symmetric attribute.
Relation-is-permanent attribute.
To create a relation:
Use the conclude action to conclude that any class or instance is related to any other class or instance.
conclude that bottle-1 is located-at washing-station
To delete a relation:
Use the conclude action to conclude that any class or instance is not related to another class or instance.
conclude that bottle-1 is not located-at washing-station
To replace a relation:
Use the conclude action to conclude that any class or instance is now related to any other class or instance, thereby breaking any existing relations.
conclude that bottle-1 is now located-at washing-station
whenever rules. G2 detects these connection and relation events:
Comparison Between Connections and Relations
This table compares the features of connections and relations:
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. 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.