![]() |
Site Archive (Complete) | |||
|
ABOUT US |
CONTACT |
ADVERTISE |
SUBSCRIBE |
SOURCE CODE |
CURRENT PRINT ISSUE |
NEWSLETTERS
|
RESOURCES
|
BLOGS
|
PODCASTS
|
CAREERS
|
||||
July 30, 2008
Disentangling Concepts in Object-Oriented SystemsEven simple class interfaces can mask complex systemsStephen Gross
A class interface can be deceptively simple, which is why Stephen finds useful this object-oriented technique for "unpacking" the underlying concepts present in a given class.
Stephen is a software engineer who works primarily in UNIX-based C++ for a medical-devices company. He can be contacted at sgross@sjm.com.
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.
Table 1: Arbitrary measurements on a globe.
Table 2: A great circle representation of a globe.
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:
That said, the requirements for a class representing a polar array are:
Now, consider a variety of approaches and refinements to the interface to such a class.
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|