Created
July 11, 2016 09:43
-
-
Save simpleprogrammer-shared/6d59329cc5954cec201fe9035102af65 to your computer and use it in GitHub Desktop.
Validate User Input, Not Developer Input
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
var milkShakeMaker = new MilkShakeMaker(); | |
var shake = milkShakeMaker.MakeShake(icecubes, milk, ingredients); | |
public class MileShakeMaker | |
{ | |
public Shake MakeShake(IEnumerable iceCubes, | |
IMilk milk, | |
IEnumerable ingredients) | |
{ | |
if(ice == null || milk == null || ingredient == null) | |
throw new InvalidArgumentException("You passed in a null, duh"); | |
if(ice.Count < 1) | |
throw new InvalidArgumentException("You need ice."); | |
if(milk.IsSpoiled) | |
throw new SpoiledMilkException(); | |
foreach(var ice in iceCubes) | |
{ | |
if(ice.IsMelted()) | |
throw new MeltedIceException(); | |
} | |
if(ingredients.Count < 1) | |
throw new InvalidArgumentException("You need some ingredients."); | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment