Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Model-View-Presenter Architecture Pattern in An...

Model-View-Presenter Architecture Pattern in Android

These slides are from my session over "Model-View-Presenter Architecture Pattern in Android" at GDG DevFest 2016, Jaipur

Avatar for Vishwajeet Srivastava

Vishwajeet Srivastava

October 02, 2016
Tweet

Other Decks in Programming

Transcript

  1. ➢ Android Developer by Profession Google Summer of Code Intern

    @Mifos Initiative Founder and Director @LNMHacks Coordinator @Cybros FOSS Guy About Me Twitter - @vishwajeets3 GitHub - @vjs3 Blog - vishwajeetsrivastava.com
  2. What is Architecture (of an app or software)? • Refers

    to the fundamental structures of a software system, the discipline of creating such structures, and the documentation of these structures. • Each structure comprises software elements, relations among them, and properties of both elements and relations. • In general terms, the architecture of a system is its 'skeleton'. It's the highest level of abstraction of a system.
  3. Why should we care about Architecture? • Like any other

    complex structure, software must be built on a solid foundation. • Tools help you to develop software easily but they doesn’t replace need of careful design of software. • Architecture ensures quality. • Keeps developer focussed on the business logic of the application. • Helps writing a clean code. • High code coverage.
  4. Android Dev without any architecture • Inherited Model-View Concept is

    present. • All the business logic is written in the View portion (i.e Activity, fragments etc). • Works fine with smaller apps with a small team or individual purpose. • Will have many problems if you want to have high code coverage for your source code. • What does it look like?
  5. Importance of MVP in android dev: • Clean code. •

    Business logic will not get cluttered with Android Code. • Easy testing (Mocking android elements get easier) • Happy life :D
  6. Commonly used architectures in android • Model-View-Presenter (MVP) • Model-View-ViewModel

    (MVVM) • Uncle BoB’s Clean Architecture • And Many more
  7. • You can use whatever seems best in your use

    case. • Every Architecture has its own pros and cons • Many people uses more than one architecture at a time • How is that possible? Which one should I choose?
  8. Model-View-Presenter Architecture Pattern What is MVP? View is a layer

    that displays data and reacts to user actions. On Android, this could be an Activity, a Fragment, an android.view.View or a Dialog. Model is a data access layer such as database API or remote server API. Presenter is a layer that provides View with data from Model. Presenter also handles background tasks.
  9. • Complex tasks are split into simpler tasks and are

    easier to solve. • Smaller objects, less bugs, easier to debug. • Testable
  10. Shall we move to the real world? • Sample Codes

    • Apps using MVP? ◦ Ribot ◦ Mifos-Self-Service App ◦ Google Sample Apps
  11. I understood what M and V, what the hell is

    P? • Presenter is the core of application • It contains our business logic • Should be written in a way that this logic can be used in another app • Presenter should do all the talking with Views as well as Model • View and Model Should only interact with each other via Presenter • Presenter should only send the data which is required by the View (nothing less or more).
  12. Third Party Libraries commonly used with MVP • Dagger 2

    (Injection) • Retrofit (generic) • RxJava (dicy :p)
  13. Who has time for all this? It's all so complex

    so we shall use an MVP library! ………………..
  14. Some Awesome Resources to begin learning MVP • Google Sample

    Apps • Ribot Blog • Ribot Boiler Plate code
  15. Bonus Slide: • Awesome Resources ◦ GitHub ◦ Android Developer’s

    channel ◦ Twitter ◦ And many more…….. • Good Practices