Click here to Skip to main content
15,885,871 members
Articles / Programming Languages / C#

Strategy Design Pattern (Case Study)

Rate me:
Please Sign up or sign in to vote.
4.83/5 (18 votes)
19 Aug 2009CPOL2 min read 62.3K   282   47  
This article shows a case study about how we use the strategy pattern to a daycare center.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using www.askbargains.com.Strategy;

namespace www.askbargains.com
{
    namespace Client
    {
        class Program
        {
            static void Main(string[] args)
            {
                //initialize a daycare object  
                DaycareContext aDayCare = new DaycareContext();

                //Kid Eliabeth is created
                Kid kid1 = new Kid();
                kid1.Name = "Elizabeth";
                kid1.Age = 3;

                //Kid Eliabeth is created
                Kid kid2 = new Kid();
                kid2.Name = "Aimee";
                kid2.Age = 4;

                //add two kids to the aDayCare object
                aDayCare.Kids.Add(kid1);
                aDayCare.Kids.Add(kid2);

                //Client determines the condation for which doctor needs to be involved.
                Console.WriteLine("Please type today's Date ==> (DD)");
                string date = Console.ReadLine();
                switch (date)
                {
                    case "15":
                        aDayCare.Doctor_on_Duty = new EyeDoctor();
                        break;
                    case "28":
                        aDayCare.Doctor_on_Duty = new SLP();
                        break;
                    default:
                        Console.WriteLine("No doctor visit today");
                        break;
                }

                //loop all the kids 
                foreach (Kid oneKid in aDayCare.Kids)
                {
                    //assign the particular kid to the doctor for the exam
                    aDayCare.Doctor_on_Duty.aKid = oneKid;
                    Console.WriteLine();
                    aDayCare.StartDoctorActivies();
                }

                Console.ReadLine();

            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
Sr Software Architect.Microsoft Certified Solutions Developer (MCSD).

Comments and Discussions