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

Whenever I need variables like x1,x2,x3,x4...... I think of a collection like List or Array

Hi ddanbe,

Why didn't I think of that. It simplifies many things! Thank you. I knew it would be simple.

-ikel

I don't see an implementation of your Joint class. But to me it seems it could contain a continuous and discrete rotation. If I'm correct, this could simplify things further I guess.

ddanbe,

At the moment, Joint only contain id number and other things but not rotation behaviour. You're right there, I could simplify things further having an interface that define rotation in Joint including axis of rotation. Hmm... back to Enterprise Architect...

Thank you for your feedback!

-ikel

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.