Skip to content

Instantly share code, notes, and snippets.

Last active June 25, 2017 16:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
The following gist shows the job of a model in MVP via an example.
class Model {
UserModelHelper userModel;
RecipeModelHelper recipeModel;
NetworkManager networkManager;
Make the constructor here and initialize the model helpers
like UserModel and other managers
/* Checks if the account is premium or not. Throws an
exception if not, otherwise proceeds with network call.
The business logic is to only give this option to
the premium account holders. This type of logic goes
in the model*/
List<Recipe> onLoadRecipes() {
if (userModel.isAccountPremium()) {
// Fetches the recipes
Result result = networkManager.getRecipes();
// Saves the recipes data
// Send the result back to the presenter.
return result.getRecipes();
} else {
/* We can show an upgrade dialog when we catch
this */
throw new UpgradeAccountException();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment