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.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)