The document discusses various iOS architecture patterns, focusing on Model-View-Controller (MVC), Model-View-Presenter (MVP), and Model-View-ViewModel (MVVM). Each pattern's structure, advantages, and disadvantages are outlined, emphasizing MVC's separation of concerns and pitfalls, MVP's clear division of responsibilities, and MVVM's benefits in testability and UI management. Additionally, it mentions challenges in implementing MVVM, particularly in more complex scenarios.
A good architecture ●Balanced distribution of responsibilities among entities with strict roles. ● Testability usually comes from the first feature. ● Ease of use and a low maintenance cost.
4.
Model-View-Controller ● A provenpattern for organizing code in complex application design ● Separates an application into three main logical components: model, view, and controller
5.
Components in MVC ●Model ○ All the data-related logic that the user works with ● View ○ Presenting data to the user ○ Handling user interaction ● Controller ○ An interface between Model and View components
6.
Realistic Cocoa MVC ●Cocoa MVC encourages you to write Massive View Controllers, because they are so involved in View’s life cycle that it’s hard to say they are separate.
7.
Advantages of MVC ●Separation of Concerns ○ the View and the Model in fact separated, but the View and the Controller are tightly coupled. ● Testability ○ you’ll probably only test your Model. ● Reusability ○ Controllers are often not reusable ○ View and model objects are easy to reuse ● The least amount of code among others patterns.
8.
Problems of MVC ●MVC frameworks tend to lead to Apps with Massive View Controllers ● Network calls, persistence, view logic, and all other sorts of code ends up in the Controller. ● This Makes Controller code ○ difficult to read ○ difficult to change ○ difficult to unit test ○ difficult to reuse
Components in MVP ●Model ○ An interface defining the data to be displayed or otherwise acted upon in the user interface ● View ○ A passive interface that displays data ○ Routes user commands to the presenter ● Presenter ○ It retrieves data from repositories (the model), and formats it for display in the view
Features of theMVP ● Distribution ○ responsibilities divided between the Presenter and the Model, with the View. ● Testability ○ we can test most of the business logic due to the View. ● Easy of use ○ the amount of code is doubled compared to the MVC, but at the same time, idea of the MVP is very clear. ● MVP in iOS means superb testability and a lot of code.
13.
Model-View-ViewModel (MVVM) ● TheMVVM treats the view controller as the View ● There is no tight coupling between the View and the Model
14.
Components in MVVM ●Model ○ Used to represent a “model” of some set of data ● View ○ Used to represent the user interface (UI) of the app ● ViewController ○ Used to set up the UI of views and handle any user interaction with these views ● View Model ○ Used to represent a model of a view controller ○ Notifies the view of any state changes
iOS MVVM Architecture ●This leaves the view (controller) with a more clearly defined task of presenting the data supplied by the view-model. ● The view-model exposes the minimum information necessary to our view controller
17.
Features of theMVVM ● Distribution ○ data gathering / logic / transforming extracted away from the complexities of a view controller ● Testability ○ the view model knows nothing about the View, this allows us to test it easily ● Easy of use ○ When the view model needs to communicate something to the view, it does so through a system of data bindings
18.
MVVM Disadvantages ● Inbigger cases, it can be hard to design the ViewModel up front in order to get the right amount of generality. ● More files to serve the architecture. ● Some people think that for simple UIs, MVVM can be overkill. ● Debugging would be bit difficult when we have complex data bindings.
Reference ● The SwiftProgramming Language (Swift 3.0.1) ● Model-View-Controller (MVC) in iOS: A Modern Approach ● iOS Architecture Patterns Demystifying MVC, MVP, MVVM and VIPER