Introduction to MV(Whatever) in Android

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →
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

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

54 slides
  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

More Decks by Elvis Lin

Other Decks in Programming