0

So i have a class called VirtualMouse, it is used to perform mouse actions such as moving and clicking.

public class VirtualMouse
{
    public VirtualMouse()
    {

    }

    public void MoveByOffset(int offsetX, int offsetY)
    {
       // Implementation.
    }

    public void MoveToPosition(Point position)
    {
        // Implementation.
    }

    public void ClickLeftButton()
    {
       // Implementation.
    }

    public void PressLeftButton()
    {
        // Implementation.
    }

    public void ReleaseLeftButton()
    {
        // Implementation.
    }
}

This is to implement basic mouse automation. Now I also wanna have the ability to create a class that is specialized, for example a HumanVirtualMouse which would have the same methods but would move the mouse in a human like way.

Should I inherit from VirtualMouse and call the base class methods in succession to create human patterns(for example I can use MoveByOffset inside a loop) or have an instance of VirtualMouse inside the HumanMouse class?

I guess i should favor inheritance because HumanMouse is-a VirtualMouse and i only need to modify the movement methods, click, press and release remain the same...

1 Answers1

2

From your description and the comment, it does not sound like you want a derived class HumanVirtualMouse. It seems you want a component which generates certain calls to MoveToPosition (or the other methods) to a virtual mouse object, something like a HumanLikeMouseController. Overriding those "Move" methods does not look necessary, not even very useful to me.

Thus I see no benefit in using inheritance here. In fact, my mental model is one of a mouse on one hand, and someone or something separate controlling it - and the code should reflect that model.

Doc Brown
  • 206,877