Model, View, Controller

Model, View, Controller (MVC) is an another software development pattern. We will use it keep everything grouped, and to have all files do only those tasks, that they supposed to do.

Models are objects that do some business logic. Models are our main objects that we use in the app. For example, in some ordering app, we would have Order, Customer, Order Item models. Models are doing all heavy lifting: they work with databases, they get info from the remote servers, etc.

Views are made for users, so they would be able to interact with our app.

Controllers are objects that connect views and models. View tells the controller what action user just made. The controller decides what should be done, and then asks the model to do it. The model works on a given tasks and passes results back to the controller. The controller now decides how to show the outcome in a view, whether to show a new screen, update current one or to show some error.

Let's use Weather app for example. A user opens the app and sees an outdated data. And now we start our MVC cycle:

MVC is a high-level abstraction pattern, and its execution may vary from platform to platform. In Rubymotion, we will have Screens as controllers, Layouts as views, and Models as Models.

Let's create a folder structure for the app. To keep everything in order, we will create separate apps for all three of these object groups inside /app folder: /app/screens for screens (or controllers), /app/layouts for layouts (or views), /app/models for models:

Now, when we have everything set up, all icons and splash screens added, all folders created, we can learn how to create user interface and screens.

Book Index | Next