MVP  Architecture Pattern

MVP Architecture Pattern

Architecture Pattern is a fundamental part of computer science. It’s the only way to maintain a project clean, expansible and testable. The patterns are recognized solutions that have been developed over the years and are considered industry standards.

In This Article , I’d like to illustrate the usage of MVP (Model-View-Presenter) Architecture Pattern As Method For Developing Android Apps with clean Architecture approach.

^^Now We Will Start to Know What is the Meaning OF Model & View & Presenter Lets starting to introduce all of this words ^^


What is Model - View - Presenter Mean !?
  • Model: the data layer ( The Model is a layer that consists of components responsible for functionalities such as fetching, generating, storing and exposing data - Any data fetched or generated in the Model layer is usually returned to the Presenter via callbacks.).
  • View: the UI layer, displays data received from Presenter, reacts to user input. On Android, we treat Activities, Fragments, and android.view.View as View from MVP.

((((( Each View should ideally have a single Presenter. The View should use its Presenter’s interface to communicate with its Presenter so that it is decoupled from any specific implementation of itsPresenter and can be tested in isolation. The View, ideally, should be lean and have no business logic. It should get data only via its Presenter and not directly from the Model layer)))).


  • Presenter: responds to actions performed on the UI layer, performs tasks on Model objects (using Use Cases), passes results of those tasks to Views (Each Presenter should ideally be paired with a single View - The Presenter handles any additional business logic and data processing that needs to be done before displaying the data. Any time consuming processing should be done on a background thread)


Should I use MVC or MVP in my project ?

There isn’t exactly a correct answer for this question. Some people will believe that MVC is the solution, others will stand with MVP and some will tend towards another solution, like MVVM for example. Each one of these approaches have advantages and disadvantages. Which means that the only way to answer the question is to understand the pros and cons of each solution, so you can make your choice wisely.

Model–view–controller ( MVC) is a software architectural pattern mostly (but not exclusively) for implementing user interfaces on computers. It divides a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user.
From wikipedia


Model–view–presenter (MVP) is a derivation of the model–view–controller (MVC) architectural pattern, and is used mostly for building user interfaces.
In MVP the presenter assumes the functionality of the “middle-man”. In MVP, all presentation logic is pushed to the presenter.
From wikipedia

In This Pic we can see the difference Between Two Patterns

Conclusion:

The MVP pattern is capable of solving some issues caused by Android’s default architecture. It makes your code easy to maintain and test. Adopting MVP may look difficult at first, but once you understand the logic behind it, the whole process is straightforward.


--Example of MVP

htts://github.com/sgzsh269/android-mvp-architecture/tree/base-mvp

In the Coming Article I will Represent MVP With An Example .

要查看或添加评论,请登录

Khaled K.的更多文章

社区洞察

其他会员也浏览了