Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simpleprogrammer-shared/80e7c7232911ceef2723335ca86358cb to your computer and use it in GitHub Desktop.
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
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