MVVM Design Pattern for building robust and scalable iOS apps
Let’s start from basic, What is a Design Pattern? It can be defined as a solution which should be allows us to reuse the code structure while developing/designing the application. Design Patterns help you to write simplified & reliable code, which can be easily understandable & reusable. In simple words, design patterns help in managing code complexity.
MVVM (Model-View-ViewModel) is one of the design patterns which allows separating business logic from user interface. MVVM (Model-View-ViewModel) is a trending structural design pattern that focused on the separation of objects into three different groups:
Model — Model is nothing but the business data or user data of your app. It is a collection of object with properties and some variable to contain data in memory. Some property of model can refer to other model object & it is called as model object.
View — View is a user interface.View display data to user & modify according to user action. Dynamic part like animation can be defined in view.
View Model — View Model is the main part of MVVM. The main responsibility of view model is to transform model information into values and display on view. It allows the user to interact with app data & modify the data according to user action.
The responsibility of View & Model is same as in MVC & MVP. View Model is the new component in MVVM.
Why To Choose MVVM Over MVC & MVP
- Main advantage of MVVM Architecture is, it improves the testability. It is very easy to write test cases for View Model.
- Responsibility of view controller is reduces as it does not have to communicate between View & Model. View Model provides transparency to view controller which made easy to interact between View & Model.
- View doesn’t have access to Model like in MVC & MVP, it has access to View Model which contains data that can be used for UI.
- MVVM made easier for developers to understand & read old code
Disadvantage of MVVM
- For simple UI , MVVM can be overkill.
- Just like for bigger UI, it i shard to design View Model.
- For complex data binding, debugging will be difficult.
MVVM will not be very useful when you start your application. As your app’s requirements change, you may need to choose different design patterns based on your changing requirements.
Thank q so much it's really help me to underatand this concept.