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

Intro to MVP, RxJava and Dagger

Intro to MVP, RxJava and Dagger

Himanshu Bansal

April 20, 2017
Tweet

Other Decks in Programming

Transcript

  1. Problems • Android does not encourage developers to write clean

    code • Many Android components viz Activity, Fragment, Broadcast Receiver, Service, AsyncTask etc. Writing your own domain components on top of these, code starts to look like a ‘spaghetti’ • It’s extremely difficult to maintain a good software design, even before scale. • Code contains dependencies concealed inside big classes, no way to test and debugging takes more time • Gradually, the code becomes less D.R.Y, more open for modification, gets loaded with generic interfaces which you dare to modify • It’s like playing a game of Go and slowly exhausting all your options
  2. Model View Presenter • Derived from the old MVC pattern

    • Helps reinforce S.O.L.I.D, K.I.S.S and D.R.Y • Writing test cases is a breeze • Handle config changes easily from one place, by caching presenters independently of View classes
  3. Dagger 2 • Better than Dagger 1, does not rely

    on runtime graph compositions and reflection • Dependency Injection Framework using Annotation Processors • Helps implement ‘D’ part of S.O.L.I.D principle • Separate class system which manages all the dependencies inside code using Modules/Components/SubComponents • Then for unit testing, these modules can be swapped with mock modules • Simplifies access to shared instances • Custom Scoped Instances • Multibinding
  4. RxAndroid • Reactive extensions written in Java, inspired from .NET

    • Simplifies the ability to chain async operations (using Schedulers) • Eliminates the need for unnecessary state variables, which can add bugs • Android can be more efficiently described as a system which operates on streams of data which are asynchronously emitted from various sources (Observables) • From touch events, broadcasts, service and network callbacks etc. All these events can be easily modeled using reactive extensions which work best with the Observer pattern • Ton of operators • Backpressure
  5. Further reading Mosby Viper Clean Code MVC vs MVP vs

    MVVM RxJava Samples Codepath Guides Google Sample - MVP Callback Hell Reactive Programming Reactive Extensions RxJava Official Wiki Activities are not UI elements Why MVP in Android ? Marvel app MVP Dribble Client MVP
  6. Medium goodness ! • Yet another MVP article • Understanding

    Dagger 2 • Dagger 2 • Dagger 2 + Rx + MVP • Android MVP Architecture and Dependency Injection • Dagger Multibinding • Activities SubComponent Multibinding