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

Using Object-Oriented Techniques for Representing Objects and Relationships

This section summarizes a number of standard object-oriented design principles that you will use when representing objects and relationships. The sections that follow describe how you implement these object-oriented design principles in G2.

Objects and Encapsulation

An object is the primitive element in an object-oriented programming environment. Unlike traditional programming languages, which separate functions and data, object-oriented programming languages combine into a single entity all the information the object needs to interact within the software environment. Structuring knowledge and activities into abstract objects helps to manage the complexity inherent in representing real-world problems as software applications.

An object contains all the data that defines the characteristics of the object and all the operations that the object can perform. In object-oriented terms, an object's data are called its attributes, and an object's operations are called its methods, as this diagram shows:


Objects can represent physical entities such as a computer system, a machine, or a network. Objects can also be conceptual, such as a database, a file, a message, a recipe, or a data type, such as a list or an array. Thus, objects are abstract data types with which you can represent a wide range of knowledge.

The technique of packaging together related information in a single entity is called encapsulation and is the essence of object-oriented design.

Encapsulation takes numerous forms in object-oriented design, as the following sections discuss.

Classes and Instances

When you design objects, you encapsulate related knowledge so that it can be shared among other objects in the application. For example, an object might be one of many "types of" similar objects, each with the same characteristics and behaviors. You represent this object-oriented principle by using:

Instances of the same class are said to be "analogous to" one another because they share the same definition.

Thus, a class encapsulates the definition of a set of similar instances. Classes provide the structure for the specific knowledge contained in its instances, and instances provide the specific characteristics and behaviors.

For example, you might define a robot class, which has characteristics such as "function," "rate," and "capacity." These characteristics are the attributes of the class. Each instance provides specific values for each of these attributes.

In addition, the robot class might define common behaviors such as "rotate," "reach," and "load program." These behaviors are the methods of the class. Each instance of a class responds the same way to the same method.

Thus, attributes say what an object knows, while methods say what an object does, as this diagram illustrates:


For information on how you implement each of these object-oriented principles in G2, see the references in this table:

For information on... See...
Implementing classes and instances
Representing Classes and Instances
Creating attributes
Using Attributes to Represent Value Types
Creating methods
Creating a Method and Creating a Method Hierarchy

Inheritance

If one class of objects shares similar characteristics and capabilities with another class of objects, you typically encapsulate the common features into a single class, which is called the superior class. A class that obtains its definition from another class is called a subclass. A subclass obtains its definition from its superior class by a mechanism called inheritance. When one class inherits its definition from another class, the subclass is said to be a "kind of" its superior class, and it only needs to define its unique characteristics and behaviors.

By creating a set of classes and subclasses that defines how different classes inherit characteristics and behaviors from other classes, you build a class hierarchy. For example, you might have a class hierarchy that defines various types of computer equipment, as this diagram shows:


For information on how to create a class hierarchy in G2, see Representing Subclasses and Class Hierarchies.

Subsystems

Another aspect of object-oriented design and encapsulation is to identify how objects interact to form subsystems. A subsystem is a set of classes or objects that collaborate to accomplish a set of higher-level responsibilities. In a subsystem, one object is a "part of" a larger, fully-functioning entity. Abstracting the higher-level capability of a subsystem into a single entity is an other example of encapsulation.

A subsystem appears to other subsystems as a single functioning entity. Internally, however, a subsystem consists of a potentially complex structure of objects that contain other objects. You implement subsystems in G2 by creating compound objects, which are objects that contain subobjects. You also implement subsystems by creating an workspace hierarchy, where objects contain subworkspaces.

This diagram illustrates a subsystem that consist of several subobjects:


For information on creating compound objects and workspace hierarchies, see Representing Compound Objects and Workspace Hierarchies.

Information Hiding

You can think of an object as a black box that knows what operations it can perform; however, an object is under no obligation to make known how it performs these operations. Thus, in well designed object-oriented systems, each object should have a public interface and a private representation.

The public interface represents the set of information and operations that any other object in the environment can know about and interact with, whereas the private representation defines the internal implementation of the object's set of capabilities, with which only the object itself needs to be concerned.

The technique of encapsulating different types of knowledge is known as information hiding and is another key feature of object-oriented design, as this diagram illustrates:


By restricting the amount of information about an object that is public, you can more easily maintain, modify, and extend the capabilities of the object.

For a discussion of how to implement information hiding in G2, see Encapsulating Your Module.

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

Copyright © 1997 Gensym Corporation, Inc.