MVPアーキテクチャ使いたい

4b7536b1ad854fa552a2cea0248bb5cc?s=47 hisaichi5518
November 29, 2015

 MVPアーキテクチャ使いたい

AndroidのMVPアーキテクチャについて

4b7536b1ad854fa552a2cea0248bb5cc?s=128

hisaichi5518

November 29, 2015
Tweet

Transcript

  1. 2.
  2. 9.

    ! ?

  3. 12.
  4. 14.
  5. 28.

    MVC

  6. 37.

    MVP

  7. 39.
  8. 41.
  9. 43.
  10. 51.

    View PresenterΛݺͼग़͢ public class UserActivity extends AppCompatActivity implements UserView {

    @Override protected void onCreate(Bundle savedInstanceState) { int userId = ...; (new UserPresenter(this)).fetchUser(userId); } @Override public void showName(String name) { mTextView.setText(name); } @Override public void showError(...) { ... } }
  11. 52.

    Presenter public class UserPresenter { UserView mView; public UserPresenter(UserView view)

    { mView = view; } public void fetchUser(int userId) { ApiClient.getInstance().create(UsersService.class).fetch(userId, new Callback<User>() { @Override public void success(User user, Response response) { mView.showName(user.getName()); } @Override public void failure(RetrofitError error) { mView.showError(error); } }); } }
  12. 57.

    Test public class UserPresenterTest { @Test public void testFetchUser() throws

    Exception { final AtomicBoolean called = new AtomicBoolean(); mMockClient.mock("/v4/users/\\d.json").to(200, "user.json"); class UserViewTest implements UserView { @Override public void showName(String name) { called.set(true); assertThat(name).isEqualTo("hisaichi5518"); } } UserPresenter presenter = new UserPresenter(new UserViewTest()); presenter.fetchUser(1); assertThat(called.get()).isEqualTo(true); } }
  13. 61.