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 [email protected].

comments powered by Disqus

Featured

  • AdaBoost Binary Classification Using C#

    Dr. James McCaffrey from Microsoft Research presents a C# program that illustrates using the AdaBoost algorithm to perform binary classification for spam detection. Compared to other classification algorithms, AdaBoost is powerful and works well with small datasets, but is sometimes susceptible to model overfitting.

  • From Core to Containers to Orchestration: Modernizing Your Azure Compute

    The cloud changed IT forever. And then containers changed the cloud. And then Kubernetes changed containers. And then microservices usurped monoliths, and so it goes in the cloudscape. Here's help to sort it all out.

  • The Well-Architected Architect on Azure

    In the dynamic field of cloud computing, the architect's role is increasingly pivotal as they must navigate a complex landscape, considering everything from the overarching architecture and individual service configurations to the various trade-offs involved. Here's help.

  • Windows Community Toolkit Update Improves Controls

    The Windows Community Toolkit advanced to version 8.1, adding new features, improving existing controls and making dependency changes.

Subscribe on YouTube