What I forgot to explicitly write in my original exposition of the API was
that the Vehicle API can be further understood if we think of inputs and
outputs.
The Vehicle API states that there is a steering-wheel
Object and that it accepts Input in the form of movement clockwise or
anti-clockwise.
In response to that input its Output is to cause
the road wheels to change their alignment relative to the vehicle and, if the
vehicle is moving forwards, cause the vehicle to turn in the direction of the
input.
That might be described, in an object oriented language such as
Java as:
package net.groklaw.vehicle;
class
SteeringWheel {
public:
/**
* The steering wheel
controls the direction of travel of
* the vehicle indirectly by
translating the driver input
* into changes in the position of the road
wheels.
*
* @param rotation degrees of rotation (+ or -) to
add to the current SteeringWheel position
* @return the new
absolute position of the SteeringWheel (where 0 is centred, negative is left
turn, positive is right turn)
*/
float rotate(float
rotation);
/**
* Get the current position of the steering
wheel
*
* @return the current +/- rotation in degrees
*/
float getPosition(void);
/**
* Force the steering
wheel to return to the neutral position
*/
void
returnToCenter(void);
};
And we might use it
thus:
import net.groklaw.vehicle.SteeringWheel;
bool
ourMethodToControlSteering(void) {
bool result = true; // assume it
works
float direction;
SteeringWheel sw = new
SteeringWheel();
sw.returnToCenter();
direction =
sw.getPosition();
System.out.println("Steering position %f",
direction);
// check the steering will rotate both ways
sw.rotate(-180);
direction = sw.getPosition();
if (direction !=
-180) {
System.out.println("Steered -180, got %f", direction);
result = false;
}
sw.returnToCenter();
sw.rotate(180);
direction = sw.getPosition();
if (direction != 180)
{
System.out.println("Steered 180, got %f", direction);
result =
false;
}
return result;
}
Other
developers could write their own implementation of class
SteeringWheel and its methods based on the API above. Our application
could make use of their implementations provided they use the same class name
and method signatures (return type, method name, argument types).
The
API does not reveal the copyrighted source-code implementation of my
class SteeringWheel. Other implementations do not need to reveal their
source-code provided they write it to match the API.
[ Reply to This | Parent | # ]
|