Skip to content

Instantly share code, notes, and snippets.

@davidliu
Last active March 31, 2019 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidliu/6d8ad76fdc3ad1b2112f181663725e57 to your computer and use it in GitHub Desktop.
Save davidliu/6d8ad76fdc3ad1b2112f181663725e57 to your computer and use it in GitHub Desktop.
public class LocalProfileAPI implements ProfileAPI {
public Profile retrieveProfile() {
/*... retrieve from DB or something ...*/
return new Profile();
}
}
class Model {
private ProfileAPI api;
@Inject
public Model(ProfileAPI api) {
this.api = api;
}
public Profile getProfile() {
return api.retrieveProfile();
}
}
class Presenter {
private Model model;
@Inject
public Presenter(Model model) {
this.model = model;
}
public void showProfile() {
Profile profile = model.getProfile();
doSomethingWithProfile();
}
private void doSomethingWithProfile() {
/*...*/
}
}
interface ProfileAPI {
public Profile retrieveProfile();
}
public class RemoteProfileAPI implements ProfileAPI {
public Profile retrieveProfile() {
/*... retrieve from Remote or something ...*/
return new Profile();
}
}
class Screen {
private Presenter presenter;
@Inject
public Screen(Presenter presenter) {
this.presenter = presenter;
}
public void onSomeEvent(){
presenter.showProfile();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment