I'm in a bit of a tricky situation where I need to use the Observer pattern but I don't really know the best way to go about it.
Here's a quick briefing on my application:
I'm implementing a GUI application that allows users to create flowcharts and mindmaps by dropping shapes onto a canvas and then manipulating the shapes by clicking, dragging, and holding. My shapes have the base class type of
MindMapComponentInstance, and my canvas has type
Canvas object acts as a kind of controller, creating and storing references to all the
MindMapComponentInstance objects when a user drops onto the canvas.
Now I need to implement mouse event functionality. Specifically, I need the
Canvas object to "watch" or "listen" to all the mouse events that are registered on the
MindMapComponentInstance objects. So, basically I have an undefined amount of publishers (the
MindMapComponentInstance objects), and one subscriber (the
To make things slightly more complicated, I need to be able to distinguish between different type of mouse events. A click, drag, hold, etc must all be distinguished by the
Canvas object, as it needs to act differently depending on the type of mouse event that is registered by the
What is the best way to implement what I need? Will the standard observer pattern suffice? Or should I do things a little differently to result in better code design?