I have an Eclipse RCP application with a ViewPart that follows the Model-View-Controller (MVC) design. The model is a POJO holding the current data. The ViewPart is the view that listens to changes on the model and reloads the UI if necessary.
In my application logic I want to fetch new data into the model when a user selects an entry from a list. Since the data is fetched from a server, I am using the Eclipse Job framework to do it in another thread, to not block the UI.
Now, I am struggling to find the best place to create and start the background jobs. Do you have any recommendations regarding this? I see two possible ways:
- In the controller. For this, the controller would also need to listen to changes in the model. Should the job notify the controller when the new data is fetched and the controller updates the model; or should I pass a reference to the model to the job which updates the model on its own?
- In the model. I have seen references which say that data fetching should be part of the model. In this ways I can directly control in the model which conditions trigger a loading of new data. This could be regarded as kind of a "business logic". But then I have a dependency on Eclipse internals within the model and so it's not anymore a standalone entity (harder to test).
Edit: I know that MVC is rather loosely defined. Would the answer be different or any clearer if I use for example the Model-View-Presenter design? IMHO in MVP the presenter has slightly better defined responsibilities.