Created
July 20, 2016 04:14
-
-
Save simpleprogrammer-shared/80e7c7232911ceef2723335ca86358cb to your computer and use it in GitHub Desktop.
3 Simple Techniques to Make APIs Easier to Use and Understand 4
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
public void ValidateCustomer(int maximumAge) | |
{ | |
//... | |
} | |
ValidateCustomer(25); | |
// Using an Age class to restrict values | |
public class Age | |
{ | |
public Age(int age) | |
{ | |
if(age < 0 || age > 130) | |
throw new Exception("Invalid age. Age must be between 0 and 130"); | |
} | |
} | |
public void ValidateCustomer(Age maximumAge) | |
{ | |
// ... | |
} | |
var customerAge = new Age(25); | |
ValidateCustomer(age); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment