SlideShare a Scribd company logo
1 of 4
Download to read offline
TASK 2: Educational Article – Model View Controller (MVC)
If you are new to the world of iOS development, chances are that in a development team, you will be
required to follow Apple’s standard Model-View-Controller (​MVC​) architecture. While the adoption
of MVC may seem confusing and aimless at first, its advantages will emerge slowly throughout the
development process and save precious time for any project or application. This article aims to
educate novice iOS developers about why it is highly recommended, how to incorporate it in an
application, and how to benefit from the advantages that MVC offers.
First, let us formally understand what MVC is:
Model-View-Controller (MVC for short) is an architectural software design pattern for organizing
information, interfaces, and interactions in various applications. It broadly breaks down any
software application into three interdependent components ​– the model, the view, and the
controller ​– with the intention of keeping internal representations of information and business logic
separate from how the information is displayed to and received from the user.
But what exactly does this mean? In order to make things a less complicated, it is important to
elucidate that MVC can be understood as an ideal to follow while developing; it is an archetype of
how to organize classes and objects in Swift according to the roles they play in the final rendition of
the application.
The Components of MVC
MVC, as its name suggests, is made up of three layers: the model, the view, and the controller. Every
class or Swift file part of an application falls into the category of one of these components based on
which area of the application it supports.
1. Model
The model is for the business logic of the application, and is where all the data for the application is
contained. Database storage and retrieval, networking code, API calls, and other backend related
particulars are all part of this component.
As a rule, the model should never be concerned with how the data it contains is being displayed to
the user, or even with how the data is being modified by the user.
2. View
The view is what the user of an application physically sees and interacts with on their device. The
different interface screens, modes of display, text fields, buttons, labels, lists, and other UI elements
are all part of the view component of MVC.
View objects are devoid of domain related data and are therefore typically reusable, for example the
UIKit components part of Xcode’s library that can be used in any application. Since the view is
unrelated to the specific data it is meant to display, it may also be modified from time to time unlike
the business logic of the application.
3. Controller
The controller is the component that mediates between the model and the view. Since the model
and view are more or less disconnected from one another, controller objects do not control how
exactly the data will be presented to the user but rather use protocols and delegates to facilitate
communication in an abstract manner.
Typically, usage related questions such as what happens when the user refreshes, how does the
application run in the background, when certain changes are forgotten before the application is quit,
etc. are concerned with the controller, as it provides the logical flow of operations when the
application is being used.
The controller can be thought of as the powerhouse of the application or the glue that works in
tandem with the model and the view.
EXERCISE: Categorize This!
Now that you have a fair idea of what goes where, try to group the following items into the
respective MVC components they fall under. To make it more challenging, try not to refer back to the
description of components above.
1. A table displaying results from a Yelp search.
2. A function used to store the profile picture of a user for a social networking application.
3. A label used to present the name of a Pokémon in battle.
4. A UITableViewDataSource method that specifies the number of rows in a table.
5. The addition of the cost of items in a UITableView to calculate an individual’s total expenditure.
6. A function that parses a JSON file obtained from a weather forecasting API call.
7. An enum that determines whether a user has been logged in or logged out.
8. A stack of card objects that you can swipe left or right on.
The answers are given at the end of this page.1
Cycle of Communication between MVC Components
The following cycle is typically the sequence that is followed when an application is used, and the
MVC components interact with each other accordingly:
● A user’s action in the view communicates to the controller that something has changed.
● The controller updates the model based on the information relayed by the user’s action in the
view.
● When the model is modified based on some network call or retrieval of data for example, it
communicates to the controller that it has been updated with some new information.
● The corresponding view objects are changed based on the new data communicated to the
controller.
1
(1) View, (2) Model, (3) View, (4) Controller, (5) Controller, (6) Model, (7) Controller, (8) View
The series of events can be summarized by the diagram below:
Examples: Interaction between Model, View, and Controller
View objects may communicate with the controller through targets or delegates. Suppose the user
interacts with a button on a UI screen by tapping it. Then, the appropriate controller is designated
as the ​target for the user’s action of touching the button, and what happens next in the application
is left to the controller.
The responsibility of carrying out the result of a user action can also ​delegated to the controller. For
example, suppose there is an image picker object that is invoked when a user tries to add a photo to
an album on an iOS application. Then, the decision on what must happen once the user has selected
the image from their camera roll (or taken a photo) could be left to the controller by setting it as
the delegate of the image picker object.
The controller listens to any changes in the model and updates the view accordingly. In the above
examples, the tapping of a button could maybe sign the user in into their account on the app, and
the listening controller(s) would be notified to take the user to their home screen. Similarly, the
image picker delegate would be informed that the particular image has been stored in the database,
and it would then facilitate the action of having the image appended to the user’s album.
Advantages of Adopting MVC
Most applications today involve the use of the MVC architecture because of the benefits described
below. Knowing about the various advantages that MVC offers for an application will help you
identify these points during the process of development and use them to your advantage.
● MVC objects tend to be ​reusable​. If their interfaces are well defined in an application, they can
more easily be implemented in other similarly structured applications.
● The adoption of MVC makes code more ​readable ​and manageable ​– this is key for large
development teams where there is heavy collaboration and developers work on different
components of the application.
● Improves ​organization as the logic layer of the application is separated from what information is
displayed or presented to the user.
● Liberty in the development process: developers working on user interface and display can focus
on the physical presentation of the application without being affected by the logic and
organization of data; developers of the model can focus more on the back-end, business logic of
the application, storage and retrieval of data, etc. without being concerned about how the
information is going to be perceived by the user. This ​minimizes the interdependency of
developers.
● There can be ​multiple objects of a single MVC component, making it easier for developers to
engage with the information and its presentation (eg: multiple view objects that display the
same data in different ways).
● The MVC pattern ​allows frequent UI changes​; while the business model and logic of an
application undergoes little change over time, more radical changes pertaining to size, colour,
font, layout, structure, and other UI elements can be easily implemented as it is separate from
the model.
● The adoption of MVC isolates different components of the application and makes it easier to
identify problems and bugs while thoroughly testing functionality. The issues therefore also
become easier to fix.
Key Takeaways
It is usually tempting to write large chunks of code in the UIViewController class as it seems to be
easier on the surface level. However, in the long run, it can cause a lot of problems as the
functionality present in the view controller grows larger and larger. This is one of the primary
reasons why it is advisable to incorporate the MVC pattern as a rule of thumb when developing any
application.
At first, it can be challenging to understand every object in terms of what exact role it plays in the
application, and to make confident decisions on which class or MVC component a block of code you
wrote should fall under. The key is to always remember the main roles of the components:
● Model – Business logic/data
● View – User interface
● Controller – Glue or mediator
In general, when you find that a view controller is starting to have an unnecessarily large amount of
code in it, it is probably wiser to write a new class and reorganize the functionality of the view
controller. Sometimes, it may also be helpful to think, ​Is this something I can reuse in other areas of
my application? ​Does this pertain solely to the data of my application or to a UI element? If you
answer yes to any of these, chances are that the code can be incorporated into the model or view
component rather than in the controller.
While there is breeding ground for debate on the virtual platforms out there in the world, the MVC
architectural pattern is widely recommended by most. It makes development and testing easier,
faster, and more collaboration-friendly, and while it may be hard to believe and a pain to employ
now, it will save you (and your team) precious amounts of effort over the course of time.

More Related Content

What's hot

Asymetric Modernization
Asymetric ModernizationAsymetric Modernization
Asymetric ModernizationPeter Presnell
 
Super applied in a sitecore migration project
Super applied in a sitecore migration projectSuper applied in a sitecore migration project
Super applied in a sitecore migration projectdodoshelu
 
The Significant role of event driven apps in software development
The Significant role of event driven apps in software development					The Significant role of event driven apps in software development
The Significant role of event driven apps in software development Shelly Megan
 
SOFTWARE REQUIREMENT SPECIFICATION FOR PROJECT
 SOFTWARE REQUIREMENT SPECIFICATION FOR PROJECT SOFTWARE REQUIREMENT SPECIFICATION FOR PROJECT
SOFTWARE REQUIREMENT SPECIFICATION FOR PROJECTAjeet Singh
 
Managing requirements by using baselines
Managing requirements by using baselinesManaging requirements by using baselines
Managing requirements by using baselinesIBM Rational software
 
Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration Platform
Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration PlatformMicrosoft SharePoint 2013 : The Ultimate Enterprise Collaboration Platform
Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration PlatformEdureka!
 
Web application architecture guide how it works types, components, best pract...
Web application architecture guide how it works types, components, best pract...Web application architecture guide how it works types, components, best pract...
Web application architecture guide how it works types, components, best pract...Katy Slemon
 
Personalizing Photos Application
Personalizing Photos ApplicationPersonalizing Photos Application
Personalizing Photos ApplicationMike Taylor
 

What's hot (9)

Asymetric Modernization
Asymetric ModernizationAsymetric Modernization
Asymetric Modernization
 
Super applied in a sitecore migration project
Super applied in a sitecore migration projectSuper applied in a sitecore migration project
Super applied in a sitecore migration project
 
The Significant role of event driven apps in software development
The Significant role of event driven apps in software development					The Significant role of event driven apps in software development
The Significant role of event driven apps in software development
 
SOFTWARE REQUIREMENT SPECIFICATION FOR PROJECT
 SOFTWARE REQUIREMENT SPECIFICATION FOR PROJECT SOFTWARE REQUIREMENT SPECIFICATION FOR PROJECT
SOFTWARE REQUIREMENT SPECIFICATION FOR PROJECT
 
Managing requirements by using baselines
Managing requirements by using baselinesManaging requirements by using baselines
Managing requirements by using baselines
 
Adf tutorial-1-134167
Adf tutorial-1-134167Adf tutorial-1-134167
Adf tutorial-1-134167
 
Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration Platform
Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration PlatformMicrosoft SharePoint 2013 : The Ultimate Enterprise Collaboration Platform
Microsoft SharePoint 2013 : The Ultimate Enterprise Collaboration Platform
 
Web application architecture guide how it works types, components, best pract...
Web application architecture guide how it works types, components, best pract...Web application architecture guide how it works types, components, best pract...
Web application architecture guide how it works types, components, best pract...
 
Personalizing Photos Application
Personalizing Photos ApplicationPersonalizing Photos Application
Personalizing Photos Application
 

Viewers also liked

Technol2
Technol2Technol2
Technol2Lauren
 
Say no to gender based violence
Say no to gender based violenceSay no to gender based violence
Say no to gender based violenceleticiaeoimairena
 
найкращі поезії про кохання
найкращі поезії про коханнянайкращі поезії про кохання
найкращі поезії про коханняNastia Dziubak
 
Sprogteknologi som oversætterens arbejdsplads bjarne poulsen
Sprogteknologi som oversætterens arbejdsplads bjarne poulsenSprogteknologi som oversætterens arbejdsplads bjarne poulsen
Sprogteknologi som oversætterens arbejdsplads bjarne poulsenBjarne Poulsen
 
LinkedIn Presentation to BUA Network South East Ireland
LinkedIn Presentation to BUA Network South East IrelandLinkedIn Presentation to BUA Network South East Ireland
LinkedIn Presentation to BUA Network South East IrelandDenis
 
iLive 2011 - Pjotr Tsvetkov: How to start an affiliate program?
iLive 2011 - Pjotr Tsvetkov: How to start an affiliate program?iLive 2011 - Pjotr Tsvetkov: How to start an affiliate program?
iLive 2011 - Pjotr Tsvetkov: How to start an affiliate program?iLive Conference
 
Musicmagazinefinalpitch 131030174627-phpapp02
Musicmagazinefinalpitch 131030174627-phpapp02Musicmagazinefinalpitch 131030174627-phpapp02
Musicmagazinefinalpitch 131030174627-phpapp02amorrison1
 
Final ppt of financial mgmt
Final ppt of financial mgmtFinal ppt of financial mgmt
Final ppt of financial mgmtPayal Tharani
 
Teori bahan isolasi-Syamsir Abduh
Teori bahan isolasi-Syamsir AbduhTeori bahan isolasi-Syamsir Abduh
Teori bahan isolasi-Syamsir AbduhTrisakti University
 
Alyson Martinez
Alyson MartinezAlyson Martinez
Alyson MartinezMrLawler
 

Viewers also liked (19)

Case presentation
Case presentationCase presentation
Case presentation
 
Technol2
Technol2Technol2
Technol2
 
Magazine mind map
Magazine mind mapMagazine mind map
Magazine mind map
 
Say no to gender based violence
Say no to gender based violenceSay no to gender based violence
Say no to gender based violence
 
Jane Kusiak
Jane Kusiak Jane Kusiak
Jane Kusiak
 
найкращі поезії про кохання
найкращі поезії про коханнянайкращі поезії про кохання
найкращі поезії про кохання
 
Parola d’ordine: differenziare!
Parola d’ordine: differenziare!Parola d’ordine: differenziare!
Parola d’ordine: differenziare!
 
Sprogteknologi som oversætterens arbejdsplads bjarne poulsen
Sprogteknologi som oversætterens arbejdsplads bjarne poulsenSprogteknologi som oversætterens arbejdsplads bjarne poulsen
Sprogteknologi som oversætterens arbejdsplads bjarne poulsen
 
LinkedIn Presentation to BUA Network South East Ireland
LinkedIn Presentation to BUA Network South East IrelandLinkedIn Presentation to BUA Network South East Ireland
LinkedIn Presentation to BUA Network South East Ireland
 
Zozaws
ZozawsZozaws
Zozaws
 
Erlazino funtzinoak
Erlazino funtzinoakErlazino funtzinoak
Erlazino funtzinoak
 
Transferencia de los distritos de riego
Transferencia de los distritos de riegoTransferencia de los distritos de riego
Transferencia de los distritos de riego
 
iLive 2011 - Pjotr Tsvetkov: How to start an affiliate program?
iLive 2011 - Pjotr Tsvetkov: How to start an affiliate program?iLive 2011 - Pjotr Tsvetkov: How to start an affiliate program?
iLive 2011 - Pjotr Tsvetkov: How to start an affiliate program?
 
Musicmagazinefinalpitch 131030174627-phpapp02
Musicmagazinefinalpitch 131030174627-phpapp02Musicmagazinefinalpitch 131030174627-phpapp02
Musicmagazinefinalpitch 131030174627-phpapp02
 
The next big thing .
The next big thing .The next big thing .
The next big thing .
 
Final ppt of financial mgmt
Final ppt of financial mgmtFinal ppt of financial mgmt
Final ppt of financial mgmt
 
Ходосевич Т.А.
Ходосевич Т.А.Ходосевич Т.А.
Ходосевич Т.А.
 
Teori bahan isolasi-Syamsir Abduh
Teori bahan isolasi-Syamsir AbduhTeori bahan isolasi-Syamsir Abduh
Teori bahan isolasi-Syamsir Abduh
 
Alyson Martinez
Alyson MartinezAlyson Martinez
Alyson Martinez
 

Similar to Task 2 - Educational Article – Model View Controller (MVC)

MVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,MobileMVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,Mobilenaral
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC StructureDipika Wadhvani
 
Android DesignArchitectures.pptx
Android DesignArchitectures.pptxAndroid DesignArchitectures.pptx
Android DesignArchitectures.pptxSafnaSaff1
 
IRJET- MVC Framework: A Modern Web Application Development Approach and Working
IRJET- MVC Framework: A Modern Web Application Development Approach and WorkingIRJET- MVC Framework: A Modern Web Application Development Approach and Working
IRJET- MVC Framework: A Modern Web Application Development Approach and WorkingIRJET Journal
 
Pattern oriented architecture for web based architecture
Pattern oriented architecture for web based architecturePattern oriented architecture for web based architecture
Pattern oriented architecture for web based architectureshuchi tripathi
 
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...CrimsonpublishersPRSP
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCAnton Krasnoshchok
 
demystifying_the_architectures_of_a_mobile_app_development.pptx
demystifying_the_architectures_of_a_mobile_app_development.pptxdemystifying_the_architectures_of_a_mobile_app_development.pptx
demystifying_the_architectures_of_a_mobile_app_development.pptxsarah david
 
demystifying_the_architectures_of_a_mobile_app_development.pdf
demystifying_the_architectures_of_a_mobile_app_development.pdfdemystifying_the_architectures_of_a_mobile_app_development.pdf
demystifying_the_architectures_of_a_mobile_app_development.pdfsarah david
 
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptx
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptxWhat Are The Benefits Of Using MVC Framework In ASP.NET Development.pptx
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptxQuickwayInfoSystems3
 
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptx
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptxWhat Are The Benefits Of Using MVC Framework In ASP.NET Development.pptx
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptxQuickwayInfoSystems3
 
A study of mvc – a software design pattern for web application development
A study of mvc – a software design pattern for web application developmentA study of mvc – a software design pattern for web application development
A study of mvc – a software design pattern for web application developmentIAEME Publication
 

Similar to Task 2 - Educational Article – Model View Controller (MVC) (20)

MVC
MVCMVC
MVC
 
MVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,MobileMVC(Model View Controller),Web,Enterprise,Mobile
MVC(Model View Controller),Web,Enterprise,Mobile
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC Structure
 
Android DesignArchitectures.pptx
Android DesignArchitectures.pptxAndroid DesignArchitectures.pptx
Android DesignArchitectures.pptx
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
 
IRJET- MVC Framework: A Modern Web Application Development Approach and Working
IRJET- MVC Framework: A Modern Web Application Development Approach and WorkingIRJET- MVC Framework: A Modern Web Application Development Approach and Working
IRJET- MVC Framework: A Modern Web Application Development Approach and Working
 
MVC
MVCMVC
MVC
 
Pattern oriented architecture for web based architecture
Pattern oriented architecture for web based architecturePattern oriented architecture for web based architecture
Pattern oriented architecture for web based architecture
 
IntroductionToMVC
IntroductionToMVCIntroductionToMVC
IntroductionToMVC
 
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
MVC Architecture: A Detailed Insight to the Modern Web Applications Developme...
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
demystifying_the_architectures_of_a_mobile_app_development.pptx
demystifying_the_architectures_of_a_mobile_app_development.pptxdemystifying_the_architectures_of_a_mobile_app_development.pptx
demystifying_the_architectures_of_a_mobile_app_development.pptx
 
demystifying_the_architectures_of_a_mobile_app_development.pdf
demystifying_the_architectures_of_a_mobile_app_development.pdfdemystifying_the_architectures_of_a_mobile_app_development.pdf
demystifying_the_architectures_of_a_mobile_app_development.pdf
 
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptx
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptxWhat Are The Benefits Of Using MVC Framework In ASP.NET Development.pptx
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptx
 
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptx
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptxWhat Are The Benefits Of Using MVC Framework In ASP.NET Development.pptx
What Are The Benefits Of Using MVC Framework In ASP.NET Development.pptx
 
A study of mvc – a software design pattern for web application development
A study of mvc – a software design pattern for web application developmentA study of mvc – a software design pattern for web application development
A study of mvc – a software design pattern for web application development
 
Design pattern
Design patternDesign pattern
Design pattern
 
Design Pattern
Design PatternDesign Pattern
Design Pattern
 
Mvc Architecture in a web based application
Mvc Architecture in a web based applicationMvc Architecture in a web based application
Mvc Architecture in a web based application
 
Mvp pattern
Mvp patternMvp pattern
Mvp pattern
 

Task 2 - Educational Article – Model View Controller (MVC)

  • 1. TASK 2: Educational Article – Model View Controller (MVC) If you are new to the world of iOS development, chances are that in a development team, you will be required to follow Apple’s standard Model-View-Controller (​MVC​) architecture. While the adoption of MVC may seem confusing and aimless at first, its advantages will emerge slowly throughout the development process and save precious time for any project or application. This article aims to educate novice iOS developers about why it is highly recommended, how to incorporate it in an application, and how to benefit from the advantages that MVC offers. First, let us formally understand what MVC is: Model-View-Controller (MVC for short) is an architectural software design pattern for organizing information, interfaces, and interactions in various applications. It broadly breaks down any software application into three interdependent components ​– the model, the view, and the controller ​– with the intention of keeping internal representations of information and business logic separate from how the information is displayed to and received from the user. But what exactly does this mean? In order to make things a less complicated, it is important to elucidate that MVC can be understood as an ideal to follow while developing; it is an archetype of how to organize classes and objects in Swift according to the roles they play in the final rendition of the application. The Components of MVC MVC, as its name suggests, is made up of three layers: the model, the view, and the controller. Every class or Swift file part of an application falls into the category of one of these components based on which area of the application it supports. 1. Model The model is for the business logic of the application, and is where all the data for the application is contained. Database storage and retrieval, networking code, API calls, and other backend related particulars are all part of this component. As a rule, the model should never be concerned with how the data it contains is being displayed to the user, or even with how the data is being modified by the user. 2. View The view is what the user of an application physically sees and interacts with on their device. The different interface screens, modes of display, text fields, buttons, labels, lists, and other UI elements are all part of the view component of MVC. View objects are devoid of domain related data and are therefore typically reusable, for example the UIKit components part of Xcode’s library that can be used in any application. Since the view is unrelated to the specific data it is meant to display, it may also be modified from time to time unlike the business logic of the application.
  • 2. 3. Controller The controller is the component that mediates between the model and the view. Since the model and view are more or less disconnected from one another, controller objects do not control how exactly the data will be presented to the user but rather use protocols and delegates to facilitate communication in an abstract manner. Typically, usage related questions such as what happens when the user refreshes, how does the application run in the background, when certain changes are forgotten before the application is quit, etc. are concerned with the controller, as it provides the logical flow of operations when the application is being used. The controller can be thought of as the powerhouse of the application or the glue that works in tandem with the model and the view. EXERCISE: Categorize This! Now that you have a fair idea of what goes where, try to group the following items into the respective MVC components they fall under. To make it more challenging, try not to refer back to the description of components above. 1. A table displaying results from a Yelp search. 2. A function used to store the profile picture of a user for a social networking application. 3. A label used to present the name of a Pokémon in battle. 4. A UITableViewDataSource method that specifies the number of rows in a table. 5. The addition of the cost of items in a UITableView to calculate an individual’s total expenditure. 6. A function that parses a JSON file obtained from a weather forecasting API call. 7. An enum that determines whether a user has been logged in or logged out. 8. A stack of card objects that you can swipe left or right on. The answers are given at the end of this page.1 Cycle of Communication between MVC Components The following cycle is typically the sequence that is followed when an application is used, and the MVC components interact with each other accordingly: ● A user’s action in the view communicates to the controller that something has changed. ● The controller updates the model based on the information relayed by the user’s action in the view. ● When the model is modified based on some network call or retrieval of data for example, it communicates to the controller that it has been updated with some new information. ● The corresponding view objects are changed based on the new data communicated to the controller. 1 (1) View, (2) Model, (3) View, (4) Controller, (5) Controller, (6) Model, (7) Controller, (8) View
  • 3. The series of events can be summarized by the diagram below: Examples: Interaction between Model, View, and Controller View objects may communicate with the controller through targets or delegates. Suppose the user interacts with a button on a UI screen by tapping it. Then, the appropriate controller is designated as the ​target for the user’s action of touching the button, and what happens next in the application is left to the controller. The responsibility of carrying out the result of a user action can also ​delegated to the controller. For example, suppose there is an image picker object that is invoked when a user tries to add a photo to an album on an iOS application. Then, the decision on what must happen once the user has selected the image from their camera roll (or taken a photo) could be left to the controller by setting it as the delegate of the image picker object. The controller listens to any changes in the model and updates the view accordingly. In the above examples, the tapping of a button could maybe sign the user in into their account on the app, and the listening controller(s) would be notified to take the user to their home screen. Similarly, the image picker delegate would be informed that the particular image has been stored in the database, and it would then facilitate the action of having the image appended to the user’s album. Advantages of Adopting MVC Most applications today involve the use of the MVC architecture because of the benefits described below. Knowing about the various advantages that MVC offers for an application will help you identify these points during the process of development and use them to your advantage. ● MVC objects tend to be ​reusable​. If their interfaces are well defined in an application, they can more easily be implemented in other similarly structured applications. ● The adoption of MVC makes code more ​readable ​and manageable ​– this is key for large development teams where there is heavy collaboration and developers work on different components of the application.
  • 4. ● Improves ​organization as the logic layer of the application is separated from what information is displayed or presented to the user. ● Liberty in the development process: developers working on user interface and display can focus on the physical presentation of the application without being affected by the logic and organization of data; developers of the model can focus more on the back-end, business logic of the application, storage and retrieval of data, etc. without being concerned about how the information is going to be perceived by the user. This ​minimizes the interdependency of developers. ● There can be ​multiple objects of a single MVC component, making it easier for developers to engage with the information and its presentation (eg: multiple view objects that display the same data in different ways). ● The MVC pattern ​allows frequent UI changes​; while the business model and logic of an application undergoes little change over time, more radical changes pertaining to size, colour, font, layout, structure, and other UI elements can be easily implemented as it is separate from the model. ● The adoption of MVC isolates different components of the application and makes it easier to identify problems and bugs while thoroughly testing functionality. The issues therefore also become easier to fix. Key Takeaways It is usually tempting to write large chunks of code in the UIViewController class as it seems to be easier on the surface level. However, in the long run, it can cause a lot of problems as the functionality present in the view controller grows larger and larger. This is one of the primary reasons why it is advisable to incorporate the MVC pattern as a rule of thumb when developing any application. At first, it can be challenging to understand every object in terms of what exact role it plays in the application, and to make confident decisions on which class or MVC component a block of code you wrote should fall under. The key is to always remember the main roles of the components: ● Model – Business logic/data ● View – User interface ● Controller – Glue or mediator In general, when you find that a view controller is starting to have an unnecessarily large amount of code in it, it is probably wiser to write a new class and reorganize the functionality of the view controller. Sometimes, it may also be helpful to think, ​Is this something I can reuse in other areas of my application? ​Does this pertain solely to the data of my application or to a UI element? If you answer yes to any of these, chances are that the code can be incorporated into the model or view component rather than in the controller. While there is breeding ground for debate on the virtual platforms out there in the world, the MVC architectural pattern is widely recommended by most. It makes development and testing easier, faster, and more collaboration-friendly, and while it may be hard to believe and a pain to employ now, it will save you (and your team) precious amounts of effort over the course of time.