Skip to content

Instantly share code, notes, and snippets.

Embed
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
recipeModel.saveRecipes(result.getRecipes());
// 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