Click here to Skip to main content
12,291,499 members (63,141 online)
Click here to Skip to main content

Stats

40K views
498 downloads
65 bookmarked
Posted

Adapter Design Pattern

, 8 Oct 2009 CPOL
This article shows a case study about how we use the Adapter Pattern to Elizabeth's Day Care Center
www.askbargains.com
www.askbargains.com.AdapteeClass
bin
Debug
www.askbargains.com.AdapteeClass.dll
Properties
www.askbargains.com.AdapterDesignPattern
bin
Debug
www.askbargains.com.AdapteeClass.dll
www.askbargains.com.AdapterDesignPattern.dll
ClassDiagram1.cd
Properties
www.askbargains.com.Client
bin
Debug
www.askbargains.com.AdapteeClass.dll
www.askbargains.com.AdapterDesignPattern.dll
www.askbargains.com.BridgeDesignPattern.dll
www.askbargains.com.BuilderDesignPattern.dll
www.askbargains.com.Client.exe
www.askbargains.com.Client.vshost.exe
www.askbargains.com.Client.vshost.exe.manifest
www.askbargains.com.PrototypeDesignPattern.dll
Properties
www.askbargains.com.suo
using System;

namespace www.askbargains.com
{  
    namespace AdapterDesignPattern
    {
        //Adapter for Non English Speaker
        public class AdapterForNonEnglishSpeaker : ITalkable
        {
            //Since the NonEnglishSpeaker is sealed. we can not directly create a child class for it.
            //we create an instance of NonEnglishSpeaker to be adapted.
            //I use the fullname here to clearly show the object is from outside of the system.
            www.askbargains.com.AdapteeClass.NonEnglishSpeaker aNonEnglishSpeakerKid = new www.askbargains.com.AdapteeClass.NonEnglishSpeaker();


            //Implement all the details to allow our system to communicate.
            #region ITalkable Members

            public void TellMeAboutNameInEnglish()
            {
                //call helper method for client to distigilish between an Adapter and Regular ITalkable objects
                aNonEnglishSpeakerKid.MethodA();
                Console.WriteLine("My name is {0}", aNonEnglishSpeakerKid.Name);
            }

            public void TellMeAboutAgeInEnglish()
            {
                aNonEnglishSpeakerKid.MethodA();
                Console.WriteLine("I am {0} years old", aNonEnglishSpeakerKid.Age.ToString());
            }

            public void TellMeAboutFavorFoodInEnglish()
            {
                Console.WriteLine("My favor food is {0}", aNonEnglishSpeakerKid.FavorFood);
            }

            #endregion
        }
    }
}

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)

Share

About the Author

Allen _ Wang
Architect
United States United States
Sr Software Architect.Microsoft Certified Solutions Developer (MCSD).

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160518.1 | Last Updated 8 Oct 2009
Article Copyright 2009 by Allen _ Wang
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid