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

MVP pattern

Avatar for Robin Robin
April 13, 2017

MVP pattern

A lightning talk about the need for such a pattern to develop an Android app.

Avatar for Robin

Robin

April 13, 2017
Tweet

More Decks by Robin

Other Decks in Programming

Transcript

  1. Code smells Testing Mocking static methods is a pain Testing

    business rules requires emulation SRP violation View is aware of business rules Regression prone, not modular You don’t want to write the tests for this
  2. How to proceed Start from the view: what are its

    responsibilities? (use case: user login) boolean userIsValid(User user); void connect(User user); void saveUser(); String[] getUserInputs(); void displayAuthError(String error); void continueFlow(); void prefillFields(String username, String fakePassword);
  3. How to proceed String[] getUserInputs(); void displayAuthError(String error); void continueFlow();

    void prefillFields(String username, String fakePassword); UserView.java interface Every view handling user login should implement this contract
  4. How to proceed UserInteractor.java interface Business logic classes handling user

    auth should implement this contract boolean userIsValid(User user); void connect(User user); void saveUser();
  5. How to proceed UserInteractor.java boolean userIsValid(User user); void connect(User user);

    void saveUser(); String[] getUserInputs(); void displayAuthError(String error); void continueFlow(); void prefillFields(String username, String fakePassword); UserView.java How to tie it all together? Recap:
  6. How to proceed UserInteractor UserView continueFlow(); getUserInputs(); displayAuthError(); prefillFields(); saveUser();

    connect(); userIsValid(); onUserConnectSuccess(); onUserConnectError(); ? Remember to conserve SRP
  7. The big reveal Business concerns are clearly separated Business rules

    are unit-testable Swappable implementations Loose coupling TDD is possible ✅ ⚠ Added complexity