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 | |||||||
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
(South pole) 200 |
100 | 100 | 100 | 100 |
0 | 1 | 2 | 3 |
8 | 9 | 10 | 11 |
16 | 17 | 18 | 19 |
24 | 25 | 26 | 27 |
32 | 33 | 34 | 35 |
40 | 41 | 42 | 43 |
48 | 49 | 50 | 51 |
56 | 57 | 58 | 59 |
200 | 200 | 200 | 200 |
60 | 61 | 62 | 63 |
52 | 53 | 54 | 55 |
44 | 45 | 46 | 47 |
36 | 37 | 38 | 39 |
28 | 29 | 30 | 31 |
20 | 21 | 22 | 23 |
12 | 13 | 14 | 15 |
4 | 5 | 6 | 7 |
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.