Strategy Pattern in .NET: Listing 2

Employer Validation Strategy

Listing 2: EmployerValidationStrategy.cs

using System;
 
namespace VSMStrategyPatternDemo
{
    public class EmployerValidationStrategy : IPersonValidationStrategy
    {
        public bool IsValid(Person person)
        {
            bool valid = false;
 
            if (person.FirstName != null && person.LastName != null && person.EIN > 0
                        && (person.DateOfBirth != null 
                        && person.DateOfBirth.Value.AddYears(-18) < DateTime.Now.AddYears(18)))
            {
                valid = true;
            }
 
            return valid;
        }
    }
}

About the Author

Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at vogelvision@gmail.com.