Global Positioning System Reference
In-Depth Information
certain distance in a specified direction. We therefore add a new method,
move(direction,distance) .
4.3
A Position Interface for Various
Coordinate Systems
Basically the GeoPoint method is now ready to be used to represent any
location of any entity on the globe. However, the earth is not a per-
fect mathematically regular body. Its shape is a rather irregular geoid.
The hard-coded implementations of the distance and move method in the
GeoPoint method are hardly ever precise on the world's surface in every
continent, country, or region. This is a typical programming problem. In-
stead of nding the best compromise for the method's implementations,
interfaces provide a way to separate what and how? What is the distance?
How is it calculated (on an ellipsoid)? Note that the roaf.util package is
not an essential part of the roaf library. It supplies useful, general default
implementations out of the box and can easily be replaced. By using an
interface with the GeoPoint method, the actual implementation is separated
from the formulas or method used.
The interface only defines method signatures 3 expected from a class:
roaf.gps.Position
public interface Position
{
// public abstract void setLatitude(double latitude);
// public abstract is not needed:
void setLatitude (double latitude);
void setLongitude(double longitude);
double getLatitude ();
double getLongitude();
double distance (Position pos);
double direction(Position pos);
void move( direction, distance )
:
}
The interface is part of the roaf.gps package and vital for the roaf li-
brary. Every position handled inside the library should be coded using the
Position interface instead of a hard-coded implementation. With this in-
terface every real-object application can use its own formula for distances.
This opens up the possibility to link external context-sensitive GPS li-
braries. One scenario might describe a racing track and require centimeter
precision, while another might deal with airplanes connecting the conti-
nents and require a quite different measure. A major purpose of libraries
(or frameworks) is to separate things that change from things that don't.
3 The method's name and parameters.
 
Search WWH ::




Custom Search