Architectural patterns in Software Engineering
Hello friends hi. This post is regarding all about Architectural Patterns in Software Engineering. Architectural Patterns isn't about any specific domain like Android or Web, It is common to all software development environment. Architectural Pattern is very important for building a robust, maintainable and testable software because its main pillar is the Separation of Concern that separate the business layer with the UI layer and provide a handy testing environment.
So an architectural pattern is a concept that solves and delineates some essential cohesive elements of a software architecture. Countless different architectures may implement the same pattern and share the related characteristics. Patterns are often defined as "strictly described and commonly available"
In Android application development there are mainly three architectural patterns which are as...
1)- MVC (Model-View-Controller)
2)- MVP (Model-View-Presenter)
3)- MVVM (Model-View-ViewModel)
So let discuss about these one by one....
1)- MVC (Model-View-Controller)
As we know that MVC stands for Model-View-Controller, It is the default architectural pattern in Android application development. It has mainly three components
a)- Model:- Model manages the data, business logic and the rules of the application.
b)- View:- View is responsible to display the data and send the user command to the controller.
c)- Controller:- Controller acts as an intermediary or a bridge between Model and View. It process all the business logic, incoming request, manipulating data using the model and interacting with the view to render the final output.
It can be shown graphically as -----
1)- MVP (Model-View-Presenter)
As we know that MVP stands for Model-View-Presenter, It is similar to the MVC only the difference is Controller is replaced by Presenter.
The problem with MVC is the tight coupling in view and controller that leads the violation of the Separation of Concern rule and we can not perform unit testing. To resolve this issue MVP came into the picture. In MVP the View and Presenter is connected through an interface. And hence the view don't know how the presenter works and vice-versa.
It also has mainly three components
a)- Model:- Model manages the data, business logic and the rules of the application.
b)- View:- View is responsible to display the data and send the user command to the Presenter.
c)- Presenter:- Controller acts as an intermediary or a bridge between Model and View. It is connecter to the view using an interface.
It can be shown graphically as -----
1)- MVVM (Model-View-ViewModel)
As we know that MVVM stands for Model-View-ViewModel, It is the most advanced and the latest architectural pattern especially for Android. It is based on Observer pattern and its also useful for the complex UI because it supports dataBinding. It has mainly three components
a)- Model:- Model manages the data, business logic and the rules of the application.
b)- View:- View is responsible to display the data and send the user command to the ViewModel.
c)- ViewModel:- ViewModel receive the request from view and respond the request from model in the form of observable that's means view just needs to observe the data or properties from the ViewModel. It resolve the uses or dependencies of using presenter that we used in MVP. And hence the code is now more scalable, maintainable and testable.
It can be shown graphically as -----
MVC vs MVP vs MVVM
| UI(View) and data-access mechanism(Model) are tightly coupled. | It resolves the problem of having a dependent View by using Presenter as a communication channel between Model and View. | This architecture pattern is more event-driven as it uses data binding and thus makes easy separation of core business logic from the View. |
| Controller and View exist with the one-to-many relationship. One Controller can select a different View based upon required operation. | The one-to-one relationship exists between Presenterand View as one Presenter class manages one View at a time. | Multiple View can be mapped with a single ViewModel and thus, the one-to-many relationship exists between View and ViewModel. |
| The View has no knowledge about the Controller. | The View has references to the Presenter. | The View has references to the ViewModel |
| Difficult to make changes and modify the app features as the code layers are tightly coupled. | Code layers are loosely coupled and thus it is easy to carry out modifications/changes in the application code. | Easy to make changes in the application. However, if data binding logic is too complex, it will be a little harder to debug the application. |
It can be shown graphically as -----
Thank You :)




Comments
Post a Comment