I'm using a variant of the MVC pattern. In my GUI code, often the need arises to synchronize "view data" (e.g., selected item) between different views.
For example, let's imagine a vector drawing program. We have two views: the image, and a listview of all objects (rectangles, squares, ...). The currently selected item should remain in sync - if you click on "Rectangle A" in the listview, the same rectangle should be highlighted in the image view.
The way I usually do it is to have a ViewState class contained in my model. Is that a good idea? If not, what would be a better solution?
class VectorDrawing { List<Object> Items; DrawingViewstate Viewstate; } class DrawingViewstate { Object SelectedItem; event SelectedItemChanged; } class ListviewController { ListviewController(VectorDrawing model) { model.Viewstate.SelectedItemChanged += ... // Subscribe to event ... } } class ImageViewController { ... // similar to the ListviewController }