Composition and a Simple Container Class
As a further demonstration of composition, there is an initial foray into designing and implementing a general container class. A general container is different from an array because it can hold different types. A general container is different from a cell array because all objects must descend from the same parent. For example, a general cShape container can hold both cStar and cDiamond objects because they both use cShape as a parent. A container is also different from a cell array because a container has a structure-like interface. The interface makes a container behave a lot like an object array. Rather than looping over each element in the container, clients can use vector syntax. Often the loop still exists; however, it is now hidden behind the container's interface. Developing a set of standard containers compatible with the general computer-engineering literature or with National Institute of Standards (NISI) definitions would be an enormous undertaking. The primary goal of the paper is to demonstrate one potential use of composition. A secondary goal is to produce a container that might be useful as is, or at least produce a container that can be easily improved.
Composition and a Simple Container Class, Page 1 of 2
< Previous page Next page > /docserver/preview/fulltext/books/pc/sbpc001e/SBPC001E_ch19-1.gif /docserver/preview/fulltext/books/pc/sbpc001e/SBPC001E_ch19-2.gif