Understanding Collections
You can read any relationship in two directions. For example, you can say Herman Melville wrote Moby Dick or Moby Dick was written by Herman Melville. You can paraphrase each of these two statements as follows:
- Herman Melville is in the set of persons who wrote Moby Dick.
- Moby Dick is in the set of books written by Herman Melville.
Although awkward, this way of articulating relationships highlights the existence of collections. The following two figures show various collections.
- The collection of books written by Herman Melville:
- The collection of persons who wrote Moby Dick:
You can think of collections as collections of objects or as collections of relationships, each with a source and a target object. The following figures show the ways to think of collections.
- The collection of books written by Herman Melville:
The figure to the left shows the collection of books written by Herman Melville as an object collection, while the figure to the right shows the same collection as a relationship collection.
- The collection of authors of Moby Dick:
The figure on the left shows the collection of authors of Moby Dick as an object collection, while the figure to the right shows the same collection as a relationship collection.
The preceding figures make clear that object collections and relationship collections are fundamentally equivalent. They both accommodate the same data. However, when you manipulate a relationship collection from a COM program, you can manipulate it either with an interface called ITargetObjectCol or with an interface called IRelationshipCol. The first interface lets you manipulate a collection as if it contains objects. The second interface lets you manipulate a collection as if it contains relationships. In Automation, if you do not specify an interface, you implicitly manipulate relationships as object collections because the RelationshipCol class implements ITargetObjectCol as its default interface.