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

Introduction to MV(Whatever) in Android

Elvis Lin
November 24, 2016

Introduction to MV(Whatever) in Android

Introduce MVC, MVP (, and a little MVVM) patterns in Android and describe why we need these patterns to reduce the complexity of our applications.

Elvis Lin

November 24, 2016
Tweet

More Decks by Elvis Lin

Other Decks in Programming

Transcript

  1. Huge Activities and Fragments • Hard to test • Impossible

    to unit test • Multiple responsibilities • Do complex animations • Modify and Retrieve data
  2. @Override
 public void onLoad() {
 Capital capital 
 = capitalModel.getCapital;


    String displayCapital = 
 capital.getCity()
 + “, ”
 + capital.getNation();
 
 view.setCapital(displayCapital);
 }
  3. @Override
 public void onLoad() {
 Capital capital 
 = capitalModel.getCapital;


    String displayCapital = 
 capital.getCity()
 + “, ”
 + capital.getNation();
 
 // Update UI
 view.setCapital(displayCapital);
 }
  4. @Mock
 ICapitalModel capitalModel;
 
 @Mock
 IView view;
 
 Presenter presenter;


    
 @Before
 public void setup() {
 …
 presenter 
 = new Presenter(userModel, view)
 }
  5. Do we really need it? class IPresenter { void onLoad()

    {
 …
 view.setCapital(displayCapital);
 }
 
 }
  6. class View {
 …
 viewModel.getDisplayCapital().
 subscribe( capital ->
 setCapital(capital));
 …


    private void setCapital(String capital){
 capitalTextView.setText(capital);
 }
 }
  7. Conclusion • Separation of Concerns • Create common language in

    your team • Android framework logic free (do your best) • Can be tested by JUnit
  8. Contact Info Elvis Lin • Github: 
 https://github.com/elvismetaphor • Blog:

    http://blog.elvismetaphor.me • Slides: https://speakerdeck.com/ elvismetaphor