bulat-icon  Articles & Case Studies  
 
 

[+]  Articles

 
     
   

MVC Design Pattern

by Raviteja
 

Introduction

 
A design pattern solves a common software engineering problem. Patterns are abstract designs, not code. You use them to help you define the structure of your data model and its interaction with the rest of your app. When you adopt a design, you adapt its general pattern to your specific needs. No matter what type of app you're creating, it's good to know the fundamental design patterns used in the frameworks. Understanding design patterns helps you use frameworks more effectively and allows you to write apps that are more reusable, more extensible, and easier to change.
 
 

MVC Design Pattern :

 
Model-View-Controller (MVC) is central to a good design for any iOS application. MVC assigns the objects in an app to one of three roles: model, view, or controller. In this pattern, models keep track of your app's data, views display your user interface and make up the content of an app, and controllers manage your views. By responding to user actions and populating views with content from the data model, controllers serve as a gateway for communication between the model and views.
 

 
A good implementation of this design pattern in your application means that each object falls into one of these groups.
 
The communication between View to Model through Controller can be best described with the following diagram:
 
MVC-DESIGN-PATTERN
 
The Model notifies the Controller of any data changes, and in turn, the Controller updates the data in the Views. The View can then notify the Controller of actions the user performed and the Controller will either update the Model if necessary or retrieve any requested data.
 
You might be wondering why you can't just ditch the Controller, and implement the View and Model in the same class, as that seems a lot easier. It all comes down to code separation and reusability. Ideally, the View should be completely separated from the Model. If the View doesn't rely on a specific implementation of the Model, then it can be reused with a different model to present some other data
 
top-icon