问题
I'm a bit confused about using the MVC pattern. We have a 3-tier architecture: data, middleware, front-end. We are developing an app for iPad which basically does the following:
- consumes a JSON service
- shows the results in some UI form
- the user interacts (taping an icon) / modifies (editing some input)
- repeat...
A business process is completed after n-iterations of the previous flow, that is, we consume a service and update the screen, the user does something and we use the response data from the previous service plus some other user input as the parameters to a second request, then the results of the second to feed the third, etc. until the process is finished.
My problem is that I don't really see how the MVC pattern fits in this. I'm working only in the front-end layer (just iPad development with Cocoa Touch), should I have the three components of MVC in the iPad application? Or just the view and controller?
My confusion comes from the fact that, as far as I understand the model would be the data layer, the controller the middleware and the view the iPad application but I feel I have to have some kind of representation of the model in the front-end layer.
Thanks in advance.
回答1:
After working a little bit more with the MVC pattern and reading many references, most of them from questions here in SO I think I can give an answer like this:
The MVC pattern is a logical separation of concerns between the components of an application. The 3-tier architecture achieves separation of concerns between the Data, the Application processing, and the Presentation but it also implies a physical separation since it is in essence a server-client architecture.
Both techniques can be used simultaneously since they can be seen as complementary.
Since the MVC pattern is a logical separation it is quite possible to have different parts of the Model in different physical locations. The same goes for the Controller, you can have different pieces of the Controller in the Mobile Device as well as in the server. All of your views are in the device.
Here's a summary of how the two techniques can be applied for developing a Server-client Mobile Application
Model
The Model is your data and the rules to modify it, that means that part of your model is in the Application processing tier. The data can be local, i.e., stored in the device which means it is in the Presentation tier or it could be remote such as in a DB and all the intermediate objects that represent which are in the Data tier.
View
The View is in the Presentation tier. This is the actual User Interface that lives on the device.
Controller
The Controller can also be distributed physically in the client and the server. This is all the code that either receives notifications from the Model and updates the View or processes events from the View and uses the Model accordingly. This puts it in the Application processing tier.
来源:https://stackoverflow.com/questions/14451444/mvc-multi-tier-mobile-application