I have built a simulation of real space rovers. My current implementation for the first rover looks like this
// a 6 wheel-rover
public class Rover1 {
private Joint joint1; // discrete rotation -- for steering
private Joint joint2; // continous rotation -- for wheel
private Joint joint3; // discrete rotation -- for steering
private Joint joint4; // continous rotation -- for wheel
private Joint joint5; // discrete rotation -- for steering
private Joint joint6; // continous rotation -- for wheel
private Joint joint7; // discrete rotation -- for steering
private Joint joint8; // continous rotation -- for wheel
private Joint joint9; // discrete rotation -- for steering
private Joint joint10; // continous rotation -- for wheel
private Joint joint11; // discrete rotation -- for steering
private Joint joint12; // continous rotation -- for wheel
private RotateJoint(Joint joint, float angle)
{
//...something
}
private DriveJoint(Joint joint, float speed)
{
//...something
}
private StopAll()
{
//...something
}
private DoUniqueThingThatTheOtherROverCantDo()
{
//...something only for this class
}
}
However, the other robot implementation looks like the following
// a 4 wheel-rover
public class Rover2 {
private Joint joint1; // discrete rotation -- for steering
private Joint joint2; // discrete rotation -- for steering
private Joint joint3; // discrete rotation -- for steering
private Joint joint4; // discrete rotation -- for steering
private Joint joint5; // continous rotation -- for wheel
private Joint joint6; // continous rotation -- for wheel
private Joint joint7; // continous rotation -- for wheel
private Joint joint8; // continous rotation -- for wheel
private RotateJoint(Joint joint, float angle)
{
//...something
}
private DriveJoint(Joint joint, float speed)
{
//...something
}
private StopAll()
{
//...something
}
private DoSomethingThatTheOtherRoverCantDo()
{
//...something only for this rover
}
}
At the moment my implementation is not abstract enough. I wonder if there is a way to make my implementation of both rover abstract enough so that when I simulate the next rover, the implementation would be easy. I am considering of using interface (composition rather than inheritance) for specifying DriveJoint()
, and StopAll()
, and DoSomethingThatTheOtherRoverCantDo()
. But how do I deal with differing number of Joint id (engineers decides the id number, not me) for differing rotational purpose? Could someone give a suggestion?
Thanks-ikel