Click here to Skip to main content
15,895,833 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.5K   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;

namespace www.askbargains.com
{
    namespace Strategy
    {
        public class EyeDoctor : Doctor
        {
            const int examFee = 80;

            public override void ExamineKid()
            {
                //exam starts
                Console.WriteLine("Dr. WANG (Eye doctor) starts examination for " + aKid.Name + " ....");
                //step 1
                Console.WriteLine("Distance Vision Eye Test in process...");
                //step 2
                Console.WriteLine("Near Vision Test in process...");
                //step 3
                Console.WriteLine("Amsler Grid Eye Test in process...");
                //step 4
                Console.WriteLine("Exam completed for" + aKid.Name);

            }

            public override void GenerateBill()
            {
                Console.WriteLine("Generating the biling info...");
                Console.WriteLine("Examination Fee : $" + examFee);
                //apply the discount for kids
                switch (aKid.Age)
                {
                    case 3:
                        Console.WriteLine("Extra 25%  discount is applied for " + aKid.Name);
                        Console.WriteLine("Total due: " + examFee * (1 - 0.25));
                        break;
                    case 4:
                        Console.WriteLine("Extra 25% discount for " + aKid.Name);
                        Console.WriteLine("Total due: " + examFee * (1 - 0.15));
                        break;
                    default:
                        Console.WriteLine("Extra 10% discount for " + aKid.Name);
                        Console.WriteLine("Total due: " + examFee * (1 - 0.10));
                        break;
                }


            }

            public override void CreateReport()
            {
                Console.WriteLine("Writing the report...");

                //I hardcode the condition here for an demo here.
                if (aKid.Name == "Elizabeth")
                    Console.WriteLine(aKid.Name + " needs the follow up check. please contact us...");
                else
                    Console.WriteLine(aKid.Name + " is fine. Thanks. ");
            }
        }
    }
}

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