Last active
June 25, 2017 16:27
-
-
Save GauravChaddha1996/6aa24d69722bcf3ae918b24f8b7d6d46 to your computer and use it in GitHub Desktop.
The following gist shows the job of a model in MVP via an example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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