I have several classes that have one base class called Tool. In the form, I have one link to a tool containing one of the lines of the specified classes. When the MouseDown event appears on the form, I call the current method of the ex method. "CurrentTool.MethodWhenMouseDown ()".
Most tools have 3 methods:
MethodWhenMouseDown() MethodWhenMouseUp() MethodWhenMouseMove()
But one or two classes only have:
MethodWhenMouseDown()
Now, which is better:
1. To use all three methods in the Tool, and classes that they do not need, simply call empty methods.
2. To implement ex interfaces. IMouseMoveListener, which will be implemented only by classes that should act when the MouseMove event occurs. Thus, if the MouseMove event occurs, we ask:
if(CurrentTool is MouseMoveListener) { (CurrentTool as IMouseMoveListener).MethodWhenMouseMove(); }
Additional Information:
The program is similar to Ms Paint - the tools are Brush, Bucket (one that MethodWhenMouseMove doesn't need), LineTool, etc.
In my PaintForm, I have one reference to the base class abstrac Tool, which stores one of the derived class. What triggers the event is pictureBox.
Have you considered the events that the tools subscribe to? - CodesInChaos
I would say that it would be good practice to have a method in the form that will be called after the appearance of evet and the method calls the siutable CurrentTool method. ex:
void MouseMoveSubscriber(object sender, MouseEventArgs e) { CurrentTool.MethodWhenMouseMove(e); }
I assume subscribing and unsubscribing to the CurrentTool method every time CurrentTool has been changed by bad practice?
I also thought that all referee instruments should be in shape, and the event would be signed by each instrument, and there would be no need for unsubscrinig. In my opinion, the biggest drawback is that every tool should check if it is CurrentTool.
What do you think about it? Thanks for the help.