Click here to Skip to main content
15,895,667 members
Articles / Programming Languages / C#

Design Patterns - nuff said !

Rate me:
Please Sign up or sign in to vote.
4.85/5 (18 votes)
2 Sep 2010CPOL16 min read 45.3K   633   74  
Principles of Design Patterns to answer why they exist, who should actually use them and their learning roadmap for beginners (using C#)
namespace Design_Pattern_Command2_1
{
    //Decouples client from creating concrete command instances.
    public class CommandsFactory
    {
        static Server targetObject;
        static NewCommand newCmd;
        static OpenCommand openCmd;
        static SaveCommand saveCmd;
        static PrintCommand printCmd;

        static CommandsFactory()
        {
            targetObject = new Server();
            newCmd = new NewCommand(targetObject);
            openCmd = new OpenCommand(targetObject);
            saveCmd = new SaveCommand(targetObject);
            printCmd = new PrintCommand(targetObject);
            printCmd.Parameter = "Hi";
        }
        public static Command GetCommand(string commandType)
        {
            switch (commandType.ToUpper())
            {
                case "NEW": return newCmd;
                case "OPEN": return openCmd;
                case "SAVE": return saveCmd;
                case "PRINT": return printCmd;
                default: return newCmd;
            }
        }
    }
}

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
Software Developer (Senior)
India India
Working as Senior Developer in US based MNC. Interested in R&D, writing/reading techinical articles, sci-fi movies, playing synthesizer.

Comments and Discussions