UI-based Application Architecture
For reducing coupling between model, view and business logic to increase unit testing compatibility different architectures are used. I am studying in the perspective of ios platform.
MVC: Model-View-Controller
Model:
Model classes are just data structure and manager of data structures like core data model classes and user-defined all model classes. The handler of core data models and json parser.
View:
Storyboards, xibs, UIView classes,
Controller:
UIViewController classes. which contain all business logic and presentation logic so this becomes a clumsy class and incompatible for unit testing.
MVP: Model-View-Presenter
Presenter - For solving the problems with Controller of MVC presenter is used in MVP. The controller class is partitioned in different view classes with its own business logic so controller class is reduced in smaller size in presenter pattern. But this also breaks SRP and unit testing problem does not solve yet using presenter class.
Model - Same as MVC
View - Same as MVC
MVVM: Model-View-ViewModel
This is a better approach than previous two.
M - Same as above
V - Same as above with UIViewController classes
ViewModel - This is completely different approach from MVC and MVP. In ViewModel, it contains only business logic without any presence of presentation logic or view components and any interaction with models. So this is unit testing supported and controller classes become slimmer than previous architectures.
Now UIViewCOntroller cannot ask to model for data rather it will request to ViewModel and it will communicate with model and send the requested data to UIViewController to present view. As it returns data needed for View not exactly given by Model, so it is called ViewModel.
Note: this need to be updated according to "clean architecture" of Uncle Bob
VIPER: View-Interactor-Presenter-Entity-Router
Interactor - Which contains the business logic only.Unlike ViewModel, it does not provide data to be presentable in view.
Presenter - This contains presentation logic means which view and how need to be shown. This communicates with Interactor to get data and create and send representable data to view which responsibility is added from ViewModel.
Entity - Same as Model
Router - View Routing will be maintained by this. Which view controller needs to be shown by this component with the required data.
Reference - https://medium.com/ios-os-x-development/ios-architecture-patterns-ecba4c38de52
Comments
Post a Comment