MVC: How to Implement Linked Views?
Posted
by
cw'
on Programmers
See other posts from Programmers
or by cw'
Published on 2014-03-06T08:31:55Z
Indexed on
2014/06/04
15:43 UTC
Read the original article
Hit count: 244
I'm developing a java application to visualize time series. I need (at least) three linked views, meaning that interaction with one of them updates the others.
The views are:
A list represents the available and currently selected time series. The selected time series are used as input for subsequent computations. Changing the selection should update the other views.
A line chart displays the available and selected time series. Time series should be selectable from here by clicking on them.
A bar chart shows aggregated data on time series. When zooming in to a period of time, the line chart should zoom in to the same period (and vice versa).
How to implement this nicely, from a software engineering point of view? I.e. I'd like to write reusable and clear, maintainable code. So I thought of the MVC pattern.
At first I liked the idea of having the three view components observing my model class and to refresh views upon being notified. But then, it didn't feel right to store view related data in the model. Storing e.g. the time series selection or plot zoom level in the model makes implications about the view which I wouldn't want in a reusable model.
On the other hand, having the controllers observe each other results in a lot of dependencies. When adding another view, I'd have to register all other views as observer of the new view and vice versa, passing around many references and introducing dependencies. Maybe another "model" storing only view-related data would be the solution?
© Programmers or respective owner