Consider a case of a form that is getting its data from a service and is implemented using the MVP pattern. Do I need to isolate the service access in a separate class or it can be kept in the Model class itself. In my particular case, the model class only acts as a pass through to the data access class that eventually calls the service. The data access class has logic that is used for service callbacks and querying the service in specific time intervals for any updates.
I am asking this, because I would like to keep my code structure as simple as possible and only use additional classes if needed. But I also do not want to simplify it so much that future maintenance/extension can become very difficult.
Simple code structure (meaning small number of classes) does not necessarily mean easy maintenance (see Ayende’s recent post on this). My suggestion is to keep to the Single Responsibility Principle (SRP). A Model’s responsibility in MVP is to encapsulate data to the view, but in your case it gets another responsibility: fetching the data from the service. Apart from this overloading of responsibilities, I see two other problems with this:
It seems to me your architecture isn’t really MVP (but without seeing the code, I might be wrong).
Also, the actual implementation of MVP pattern depends on the GUI technology you are using. My general suggestions:
UPDATE: answer to your comment:
If I understand correctly, you expose events/callbacks in the model for handling exceptions. Then you let the view fetch data, and in case a service call fails, the presenter handles this by (again) calling the view to let the user know the service failed. I see several problems with this approach:
My usual approach is for the presenter to do all the fetching and exception handling before the view gets its hands on the model data. That way I don’t need any callbacks in the model, since I can handle exceptions with simple try-catch blocks in the presenter. The model becomes just a holder of static data and not a gateway to backend services.