A class interface can be deceptively simple. Even though it may consist of only a few functions, those few functions may confound a number of distinct concepts. Consider, for instance, a class whose interface consists of only three functions: getStandingBlueBall(), getSittingRedDoor(), and getRunningYellowDog(). There are, in fact, three distinct concepts bound up in this interface: action (standing, sitting, or running), color (blue, red, or yellow), and object (ball, door, or dog). Although these three functions are named in accordance with their respective purposes, these single-token names do not clearly distinguish the three aforementioned concepts. Using object-oriented techniques, you can better "unpack" a class interface to distinguish the various concepts bound up in it. To illustrate these techniques, consider how best to implement the interface to a polar array class.
Overview of a Polar Array
A polar array is a representation of numeric measurements on a globe. Each measurement (altitude, for instance) is located at a unique intersection of a latitude and longitude. If a globe is subdivided into 8 latitudes and 8 longitudes, there are 8×8=64 unique measurements on the polar array, at each unique intersection of a latitude and longitude. In addition, there are measurements at the north and south poles. A set of arbitrary measurements on a globe with 8 latitudes and 8 longitudes might look something like Table 1.
You can also specify a location via a "great circle" coordinate. A great circle is a longitude that traverses the entire globe, rather than half of it. Imagine starting your traversal of the globe at the North Pole. Pick a longitude (such as #3). Follow the longitude south along the front of the globe until you reach the South Pole. Follow the longitude north along the backside of the globe. Technically, you are now traversing longitude #7 (in the geographic coordinate system). In the great circle coordinate system, you are still traversing the same longitude. Thus, the measurements on a globe with 8 latitudes and 8 longitudes are described by an 18-row-by-4-column matrix. A great circle representation of the globe just described would look like Table 2.
|(North pole) 100|
|(South pole) 200|
To simplify the internal class implementation, the actual measurements on the globe will be represented by a vector of values, in which the geographic coordinates will be listed in row-major form first, followed by the values at the North and South Poles, respectively:
1 2 ... 63 64 100 200
That said, the requirements for a class representing a polar array are:
- Accept a set of measurements at construction and store them.
- Provide the measurement at a location specified by an absolute index coordinate.
- Provide the measurement at a location specified by a geographic coordinate.
- Provide the measure at a location specified by a great circle coordinate.
Now, consider a variety of approaches and refinements to the interface to such a class.