3.1 Associating Objects in C++
An
association is an organized, interacting group of object that are
typically objects of different classes. Each object in the association
performs a specialized role in the group and interacts with other
objects as needed to perform its role as an individual and as a
collaborating member of a larger assembly. The interacting
objects may be of different classes or of the same class. When the
interacting objects are of different classes, the
definition of one class must refer to objects of another class. When
the objects are in the same class, the definition of the class must
refer to itself in some way.
Objects that interact with one another must provide methods by which
the interacting objects can become acquainted with one another. These
methods allow the designer/programmer to "connect" one object to the
other or to "glue" the two objects together. Methods for
interconnecting objects are usually defined using one, or possibly
both, of two techniques:
- an operation of one class take as its parameters objects that are
of the same or a different class, or
- the value returned by an operation in one class is an object of
the same or a different class.
Both of these techniques will be illustrated by revising the definition
of the Frame class and by introducing new classes that will allow the
construction of a simple, useful association of objects.
Last Updated: July 3, 1996 / kafura@cs.vt.edu