Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Associations

 

An association is an ordered pair of objects. The first element of the pair is called the key ; the second element is the value  associated with the given key.

Associations are useful for storing information in a database  for later retrieval. E.g., a database can be viewed as a collection of key-and-value pairs. The information associated with a given key is retrieved from the database by searching the database for an the ordered pair in which the key matches the given key.

An association is like a container in that it contains two objects--the key and the value. On the other hand, an association is fundamentally different from a container since the contained objects are treated very differently. Normally, the objects in a container are not distinguished one from another. In an association, the two contained objects are distinct--one of them is the key and the other is a value associated with the key.

Program gif gives the declaration of the concrete object class Association. The declaration of the Association class is like that of Container class in that both of them are derived from the same set of base classes--Object and Ownership.

   program5223
Program: Association Class Definition

An association has two member variables, key and value, both of which are of type pointer to Object. Since pointers are used, the Association class implements indirect containment.




next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.