static void Main(string[] args) { Developer dev = new Developer(); dev.Name = "Michael"; dev.Role = "Software Engineer"; dev.PreferredLanguage = "C#"; Developer devCopy = (Developer)dev.Clone(); devCopy.Name = "Bob"; // Role and PreferredLanguage will be copies of the above Console.WriteLine(dev.GetDetails()); Console.WriteLine(devCopy.GetDetails()); Typist typist = new Typist(); typist.Name = "Tom"; typist.Role = "Typist"; typist.WordsPerMinute = 150; Typist typistCopy = (Typist)typist.Clone(); typistCopy.Name = "Jerry"; typistCopy.WordsPerMinute = 110; // Role and WordsPerMinute will be copies of the above Console.WriteLine(typist.GetDetails()); Console.WriteLine(typistCopy.GetDetails()); Console.ReadKey(); }
private static void Ex_P1_BasicExample_v1() { Console.WriteLine("Start of P1_BasicExample_v1"); Developer dev = new Developer(); dev.Name = "Rahul"; dev.Role = "Team Leader"; dev.PreferredLanguage = "C#"; Developer devCopy = (Developer)dev.Clone(); devCopy.Name = "Arif"; //Not mention Role and PreferredLanguage, it will copy above Console.WriteLine(dev.GetDetails()); Console.WriteLine(devCopy.GetDetails()); Typist typist = new Typist(); typist.Name = "Monu"; typist.Role = "Typist"; typist.WordsPerMinute = 120; Typist typistCopy = (Typist)typist.Clone(); typistCopy.Name = "Sahil"; typistCopy.WordsPerMinute = 115;//Not mention Role, it will copy above Console.WriteLine(typist.GetDetails()); Console.WriteLine(typistCopy.GetDetails()); Console.WriteLine("End of P1_BasicExample_v1"); }
static void Main(string[] args) { Developer dev = new Developer(); dev.Name = "Rahul"; dev.Role = "Team Leader"; dev.PreferredLanguage = "C#"; Developer devCopy = (Developer)dev.Clone(); devCopy.Name = "Arif"; //Not mention Role and PreferredLanguage, it will copy above Console.WriteLine(dev.GetDetails()); Console.WriteLine(devCopy.GetDetails()); Typist typist = new Typist(); typist.Name = "Monu"; typist.Role = "Typist"; typist.WordsPerMinute = 120; Typist typistCopy = (Typist)typist.Clone(); typistCopy.Name = "Sahil"; typistCopy.WordsPerMinute = 115; //Not mention Role, it will copy above Console.WriteLine(typist.GetDetails()); Console.WriteLine(typistCopy.GetDetails()); Console.ReadKey(); }
void EfGuesses(string[] words) { if (!string.IsNullOrWhiteSpace(words[0])) { if (words[0].ToLower() == "stop") { this.AdvanceToNext(ChildId); } RedrawNode(); BottomMessage = string.Empty; foreach (string word in words) { BottomMessage += "...# " + word; } BottomMessage = "\"You are thinking: " + BottomMessage + "...?\"#"; CursorTop = MeasureMessage(BottomMessage); CursorLeft = WindowLeft; Typist.FlowingText(BottomMessage, ConsoleColor.DarkGreen); WriteLine(); WriteLine(); Typist.FlowingText("Efeliah opens her eyes,# smiling warmly at you.#"); } PrepareForAction(true); //display prompt without standard refuse }
public NStory(NodeBase node) : base(node) { this.Init(); ///go to bottom line CursorTop = WindowTop + WindowHeight - 2; CursorLeft = WindowLeft; Typist.WaitForKey(0); this.AdvanceToNext(ChildId); }
internal override void TabPressed() { CursorTop = WindowHeight - 4; CursorLeft = WindowLeft; ForegroundColor = ConsoleColor.DarkGray; WriteLine("Type something for Efeliah to guess. Type 'stop' to stop the guessing session."); CursorTop = WindowHeight - 1; CursorLeft = 0; Typist.RenderPrompt(keysPressed); }
public static void Init(this NodeBase node) { // start text Clear(); ForegroundColor = ConsoleColor.DarkCyan; //narrator, default color string text; if (node.IsVisited && node.AltText != null) { text = node.AltText; } else { text = node.Text; } Typist.RenderText(!node.IsVisited, text); }
static void PrototypeCalling() { Developer dev = new Developer(); dev.Name = "Ann"; dev.Role = "Team Leader"; dev.PreferredLanguage = "C#"; Developer devCopy = (Developer)dev.Clone(); devCopy.Name = "Anna"; //Not mention Role and PreferredLanguage, it will copy above Console.WriteLine(dev.GetDetails()); Console.WriteLine(devCopy.GetDetails()); Typist typist = new Typist(); typist.Name = "Beta"; typist.Role = "Typist"; typist.WordsPerMinute = 120; Typist typistCopy = (Typist)typist.Clone(); typistCopy.Name = "Betty"; typistCopy.WordsPerMinute = 115;//Not mention Role, it will copy above Console.WriteLine(typist.GetDetails()); Console.WriteLine(typistCopy.GetDetails()); }
void RecursiveDialogues(int lineId = 0, bool isLineFlowing = true, bool isFirstDraw = false) //lineid iterates over elements of dialogues[] { if (lineId == 0 && !isFirstDraw) { this.Init(); } if (IsVisited) { isLineFlowing = false; } // else, it depends Dialogue currentLine = Dialogues[lineId]; //cureent object selected in the iteration #region Drawing base element of the Dialog object (speech part) if (currentLine.PreComment != null) { Typist.RenderNonSpeechPart(isLineFlowing, currentLine.PreComment); WriteLine(); WriteLine(); } if (currentLine.Line != null) { Typist.RenderLine(isLineFlowing, currentLine.Line, (ConsoleColor)currentLine.Actor, currentLine.IsTelepathy); } if (currentLine.Comment != null) { Typist.RenderNonSpeechPart(isLineFlowing, currentLine.Comment); } WriteLine(); WriteLine(); if (currentLine.Break || (IsLast && Dialogues.Count == Dialogues.IndexOf(currentLine) + 1)) { Typist.WaitForKey(2); //pause if it's marked as break or if it's last line of chapter Clear(); } #endregion if (currentLine.ChildId.HasValue) //if it encounters a link, jump to the node { Typist.WaitForKey(2); this.AdvanceToNext(currentLine.ChildId.Value); } if (currentLine.Replies != null && currentLine.Replies.Any()) //if there are replies inside, display choice { for (int i = 0; i < Dialogues[lineId].Replies.Count; i++) //draw the replies, select them { if (i == selectedRow) { BackgroundColor = ConsoleColor.DarkCyan; ForegroundColor = ConsoleColor.White; } Write("\t"); Write((i + 1) + ". " + Dialogues[lineId].Replies[i].Line); ResetColor(); ForegroundColor = ConsoleColor.DarkCyan; WriteLine(); CursorLeft = WindowLeft; } while (KeyAvailable) { ReadKey(true); } key = ReadKey(true); if (key.Key == ConsoleKey.Enter) { Clear(); if (currentLine.Replies[selectedRow].ChildId.HasValue) //on selecion, either { this.AdvanceToNext(currentLine.Replies[selectedRow].ChildId.Value); //navigate to node specified in selected reply } else //or jump to the next line { RecursiveDialogues(Dialogues.FindIndex(l => l.LineName == currentLine.Replies[selectedRow].NextLine)); } } if ((key.Key == ConsoleKey.UpArrow || key.Key == ConsoleKey.LeftArrow) && selectedRow > 0) { selectedRow--; } if ((key.Key == ConsoleKey.DownArrow || key.Key == ConsoleKey.RightArrow) && selectedRow < Dialogues[lineId].Replies.Count - 1) { selectedRow++; } do { if (lineId <= 0) { break; } lineId--; }while (Dialogues[lineId].Break == false); if (Dialogues[lineId].Break) { lineId++; } Clear(); RecursiveDialogues(lineId, false); //redraw the node to allow the selection effect } else { if (!string.IsNullOrWhiteSpace(currentLine.NextLine)) { int nextLineId = Dialogues.FindIndex(l => l.LineName == currentLine.NextLine); RecursiveDialogues(nextLineId, isLineFlowing); } else if (Dialogues.Count > lineId + 1) { RecursiveDialogues(lineId + 1, isLineFlowing); } this.AdvanceToNext(ChildId); } }
private static void Main(string[] args) { #region AbstactFactoryDesignPattern /* Factory factory = new Factory(); * IVehicleFactory bike = factory.GetVehicle(EVehicleType.Bike); * bike.Drive(); * IVehicleFactory scooter = factory.GetVehicle(EVehicleType.Scooter); * scooter.Drive(); * IVehicleFactory car = factory.GetVehicle(EVehicleType.Car); * car.Drive(); * IVehicleFactory bus = factory.GetVehicle(EVehicleType.Bus); * bus.Drive(); * IVehicleFactory lorry = factory.GetVehicle(EVehicleType.Lorry); * lorry.Drive(); * IVehicleFactory train = factory.GetVehicle(EVehicleType.Train); * train.Drive(); * IVehicleFactory ship = factory.GetVehicle(EVehicleType.Ship); * ship.Drive(); * IVehicleFactory helicopter = factory.GetVehicle(EVehicleType.Helicopter); * helicopter.Drive(); */ #endregion AbstactFactoryDesignPattern #region Adapter ITarget Itarget = new EmployeeAdapter(); ThirdPartyBillingSystem client = new ThirdPartyBillingSystem(Itarget); client.ShowEmployeeList(); #endregion Adapter #region Bridge IMessageSender email = new EmailSender(); IMessageSender queue = new MSMQSender(); IMessageSender web = new WebServiceSender(); Message message = new SystemMessage(); message.Subject = "Test Message"; message.Body = "Hi, This is a Test Message"; message.MessageSender = email; message.Send(); message.MessageSender = queue; message.Send(); message.MessageSender = web; message.Send(); UserMessage usermsg = new UserMessage(); usermsg.Subject = "Test Message"; usermsg.Body = "Hi, This is a Test Message"; usermsg.UserComments = "I hope you are well"; usermsg.MessageSender = email; usermsg.Send(); #endregion Bridge #region Builder var vehicleCreator = new VehicleCreator(new HeroBuilder()); vehicleCreator.CreateVehicle(); var vehicle = vehicleCreator.GetVehicle(); vehicle.ShowInfo(); Console.WriteLine("---------------------------------------------"); vehicleCreator = new VehicleCreator(new HondaBuilder()); vehicleCreator.CreateVehicle(); vehicle = vehicleCreator.GetVehicle(); vehicle.ShowInfo(); #endregion Builder #region ChainOfResponsiblity Approver rohit = new Clerk(); Approver rahul = new AssistantManager(); Approver manoj = new Manager(); rohit.Successor = rahul; rahul.Successor = manoj; // Generate and process loan requests var loan = new Loan { Number = 2034, Amount = 24000.00, Purpose = "Laptop Loan" }; rohit.ProcessRequest(loan); loan = new Loan { Number = 2035, Amount = 42000.10, Purpose = "Bike Loan" }; rohit.ProcessRequest(loan); loan = new Loan { Number = 2036, Amount = 156200.00, Purpose = "House Loan" }; rohit.ProcessRequest(loan); #endregion ChainOfResponsiblity #region Command Console.WriteLine("Enter Commands (ON/OFF) : "); string cmd = Console.ReadLine(); Light lamp = new Light(); ICommand switchUp = new FlipUpCommand(lamp); ICommand switchDown = new FlipDownCommand(lamp); Switch s = new Switch(); if (cmd == "ON") { s.StoreAndExecute(switchUp); } else if (cmd == "OFF") { s.StoreAndExecute(switchDown); } else { Console.WriteLine("Command \"ON\" or \"OFF\" is required."); } #endregion Command #region Composite Employee Rahul = new Employee { EmpID = 1, Name = "Rahul" }; Employee Amit = new Employee { EmpID = 2, Name = "Amit" }; Employee Mohan = new Employee { EmpID = 3, Name = "Mohan" }; Rahul.AddSubordinate(Amit); Rahul.AddSubordinate(Mohan); Employee Rita = new Employee { EmpID = 4, Name = "Rita" }; Employee Hari = new Employee { EmpID = 5, Name = "Hari" }; Amit.AddSubordinate(Rita); Amit.AddSubordinate(Hari); Employee Kamal = new Employee { EmpID = 6, Name = "Kamal" }; Employee Raj = new Employee { EmpID = 7, Name = "Raj" }; Contractor Sam = new Contractor { EmpID = 8, Name = "Sam" }; Contractor tim = new Contractor { EmpID = 9, Name = "Tim" }; Mohan.AddSubordinate(Kamal); Mohan.AddSubordinate(Raj); Mohan.AddSubordinate(Sam); Mohan.AddSubordinate(tim); Console.WriteLine("EmpID={0}, Name={1}", Rahul.EmpID, Rahul.Name); foreach (Employee manager in Rahul) { Console.WriteLine("\n EmpID={0}, Name={1}", manager.EmpID, manager.Name); foreach (var employee in manager) { Console.WriteLine(" \t EmpID={0}, Name={1}", employee.EmpID, employee.Name); } } #endregion Composite #region Decorator HondaCity car = new HondaCity(); Console.WriteLine("Honda City base price are : {0}", car.Price); SpecialOffer offer = new SpecialOffer(car); offer.DiscountPercentage = 25; offer.Offer = "25 % discount"; Console.WriteLine("{1} @ Diwali Special Offer and price are : {0} ", offer.Price, offer.Offer); #endregion Decorator #region Facade CarFacade facade = new CarFacade(); facade.CreateCompleteCar(); #endregion Facade #region Flyweight ShapeObjectFactory sof = new ShapeObjectFactory(); IShape shape = sof.GetShape("Rectangle"); shape.Print(); shape = sof.GetShape("Rectangle"); shape.Print(); shape = sof.GetShape("Rectangle"); shape.Print(); shape = sof.GetShape("Circle"); shape.Print(); shape = sof.GetShape("Circle"); shape.Print(); shape = sof.GetShape("Circle"); shape.Print(); int NumObjs = sof.TotalObjectsCreated; Console.WriteLine("\nTotal No of Objects created = {0}", NumObjs); #endregion Flyweight #region FactoryDesignPattern Factory factory = new Factory(); FactoryDesignPattern.IVehicleFactory bike = factory.GetVehicle(EVehicleType.Bike); bike.Drive(); FactoryDesignPattern.IVehicleFactory scooter = factory.GetVehicle(EVehicleType.Scooter); scooter.Drive(); FactoryDesignPattern.IVehicleFactory fcar = factory.GetVehicle(EVehicleType.Car); fcar.Drive(); FactoryDesignPattern.IVehicleFactory bus = factory.GetVehicle(EVehicleType.Bus); bus.Drive(); FactoryDesignPattern.IVehicleFactory lorry = factory.GetVehicle(EVehicleType.Lorry); lorry.Drive(); FactoryDesignPattern.IVehicleFactory train = factory.GetVehicle(EVehicleType.Train); train.Drive(); FactoryDesignPattern.IVehicleFactory ship = factory.GetVehicle(EVehicleType.Ship); ship.Drive(); FactoryDesignPattern.IVehicleFactory helicopter = factory.GetVehicle(EVehicleType.Helicopter); helicopter.Drive(); #endregion FactoryDesignPattern #region Prototype Developer dev = new Developer(); dev.Name = "Rahul"; dev.Role = "Team Leader"; dev.PreferredLanguage = "C#"; Developer devCopy = (Developer)dev.Clone(); devCopy.Name = "Arif"; //Not mention Role and PreferredLanguage, it will copy above Console.WriteLine(dev.GetDetails()); Console.WriteLine(devCopy.GetDetails()); Typist typist = new Typist(); typist.Name = "Monu"; typist.Role = "Typist"; typist.WordsPerMinute = 120; Typist typistCopy = (Typist)typist.Clone(); typistCopy.Name = "Sahil"; typistCopy.WordsPerMinute = 115;//Not mention Role, it will copy above Console.WriteLine(typist.GetDetails()); Console.WriteLine(typistCopy.GetDetails()); #endregion Prototype #region Proxy ProxyClient proxy = new ProxyClient(); Console.WriteLine("Data from Proxy Client = {0}", proxy.GetData()); #endregion Proxy #region Singleton EagerSingleton.Instance.Show(); LazySingleton.Instance.Show(); Singleton.Instance.Show(); #endregion Singleton Console.ReadKey(); }
static void Main(string[] args) { //Behavioral Patterns Console.WriteLine("Behavioral"); // Wait for user Console.ReadKey(); //1 - Command Console.WriteLine("Command"); Console.WriteLine("Enter Commands (ON/OFF) : "); string cmd = Console.ReadLine(); Light lamp = new Light(); ICommand switchUp = new FlipUpCommand(lamp); ICommand switchDown = new FlipDownCommand(lamp); Switch s = new Switch(); if (cmd == "ON") { s.StoreAndExecute(switchUp); } else if (cmd == "OFF") { s.StoreAndExecute(switchDown); } else { Console.WriteLine("Command \"ON\" or \"OFF\" is required"); } // Wait for user Console.ReadKey(); //2 - Chain of responsability Console.WriteLine("Chain of responsability"); Approver rohit = new Clerk(); Approver rahul = new AssistantManager(); Approver manoj = new Manager(); rohit.Successor = rahul; rahul.Successor = manoj; var loan = new Loan { Number = 2034, Amount = 24000.00, Purpose = "Laptop Loan" }; rohit.ProcessRequest(loan); loan = new Loan { Number = 2035, Amount = 42000.10, Purpose = "Bike Loan" }; rohit.ProcessRequest(loan); loan = new Loan { Number = 2036, Amount = 156200.00, Purpose = "House Loan" }; rohit.ProcessRequest(loan); // Wait for user Console.ReadKey(); //3 - Memento Console.WriteLine("Memento"); SalesProspect sp = new SalesProspect(); sp.Name = "Noel van Halen"; sp.Phone = "(412) 256-0990"; sp.Budget = 25000.0; // Store internal state ProspectMemory m = new ProspectMemory(); m.Memento = sp.SaveMemento(); // Continue changing originator sp.Name = "Leo Welch"; sp.Phone = "(310) 209-7111"; sp.Budget = 1000000.0; // Restore saved state sp.RestoreMemento(m.Memento); // Wait for user Console.ReadKey(); //Creational Patterns Console.WriteLine("Creational"); // Wait for user Console.ReadKey(); //1-Singleton Console.WriteLine("Singleton"); Singleton.Instance.Show(); // Wait for user Console.ReadKey(); //2-Prototype Console.WriteLine("Prototype"); Developper dev = new Developper { Name = "Antoine", Role = "Team Leader", PrefferedLanguage = "C#", WordsPerMinute = 42 }; Typist typ = new Typist { Name = "Casper", Role = "Typist", WordsPerMinute = 175 }; Console.WriteLine(typ.GetDetails()); Console.WriteLine(dev.GetDetails()); // Wait for user Console.ReadKey(); //3-AbstractFactory Console.WriteLine("Abstract Factory"); DesignPatterns.Creational.AbstractFactory.Sample.VehiculeFactory honda = new HondaFactory(); VehiculeClient hondaclient = new VehiculeClient(honda, "Regular"); Console.WriteLine("****** Honda ******"); Console.WriteLine(hondaclient.GetBikeName()); Console.WriteLine(hondaclient.GetScooterName()); VehiculeClient hondaclient2 = new VehiculeClient(honda, "Sports"); Console.WriteLine(hondaclient.GetBikeName()); Console.WriteLine(hondaclient.GetScooterName()); DesignPatterns.Creational.AbstractFactory.Sample.VehiculeFactory hero = new HondaFactory(); VehiculeClient heroclient = new VehiculeClient(hero, "Regular"); Console.WriteLine("****** Hero ******"); Console.WriteLine(heroclient.GetBikeName()); Console.WriteLine(heroclient.GetScooterName()); VehiculeClient heroclient2 = new VehiculeClient(hero, "Sports"); Console.WriteLine(heroclient.GetBikeName()); Console.WriteLine(heroclient.GetScooterName()); // Wait for user Console.ReadKey(); //4- Factory Method Console.WriteLine("Factory Method"); DesignPatterns.Creational.FactoryMethod.Sample.VehiculeFactory factory = new ConcreteVehiculeFactory(); IFactory scooter = factory.GetVehicule("Scooter"); scooter.Drive(10); IFactory bike = factory.GetVehicule("Bike"); bike.Drive(20); // Wait for user Console.ReadKey(); //5- Builder Console.WriteLine("Builder"); var vehicleCreator = new VehicleCreator(new HeroBuilder()); vehicleCreator.CreateVehicle(); var vehicle = vehicleCreator.GetVehicle(); vehicle.ShowInfo(); Console.WriteLine("---------------------------------------------"); vehicleCreator = new VehicleCreator(new HondaBuilder()); vehicleCreator.CreateVehicle(); vehicle = vehicleCreator.GetVehicle(); vehicle.ShowInfo(); // Wait for user Console.ReadKey(); //Structural Console.WriteLine("Structural"); // Wait for user Console.ReadKey(); //1 - Proxy Console.WriteLine("Proxy"); ProxyClient proxy = new ProxyClient(); Console.WriteLine("Data from Proxy Client = {0}", proxy.GetData()); // Wait for user Console.ReadKey(); //2 - Flyweight Console.WriteLine("Flyweight"); ShapeObjectFactory sof = new ShapeObjectFactory(); IShape shape = sof.GetShape("Rectangle"); shape.Print(); shape = sof.GetShape("Rectangle"); shape.Print(); shape = sof.GetShape("Rectangle"); shape.Print(); shape = sof.GetShape("Circle"); shape.Print(); shape = sof.GetShape("Circle"); shape.Print(); shape = sof.GetShape("Circle"); shape.Print(); int NumObjs = sof.TotalObjectsCreated; Console.WriteLine("\nTotal No of Objects created = {0}", NumObjs); // Wait for user Console.ReadKey(); //3 - Facade Console.WriteLine("Facade"); CarFacade facade = new CarFacade(); facade.CreateCompleteCar(); // Wait for user Console.ReadKey(); //4 - Bridge Console.WriteLine("Bridge"); IMessageSender email = new EmailSender(); IMessageSender queue = new MSMQSender(); IMessageSender web = new WebServiceSender(); Message message = new SystemMessage(); message.Subject = "Test Message"; message.Body = "Hi, This is a Test Message"; message.MessageSender = email; message.Send(); message.MessageSender = queue; message.Send(); message.MessageSender = web; message.Send(); UserMessage usermsg = new UserMessage(); usermsg.Subject = "Test Message"; usermsg.Body = "Hi, This is a Test Message"; usermsg.UserComments = "I hope you are well"; usermsg.MessageSender = email; usermsg.Send(); // Wait for user Console.ReadKey(); //5 - Adapter Console.WriteLine("Adapter"); ITarget Itarget = new EmployeeAdapter(); ThirdPartyBillingSystem client = new ThirdPartyBillingSystem(Itarget); client.ShowEmployeeList(); // Wait for user Console.ReadKey(); //6 - Decorator Console.WriteLine("Decorator"); HondaCity car = new HondaCity(); Console.WriteLine("Honda City base price are : {0}", car.Price); SpecialOffer offer = new SpecialOffer(car); offer.DiscountPercentage = 25; offer.Offer = "25 % discount"; Console.WriteLine("{1} @ Diwali Special Offer and price are : {0} ", offer.Price, offer.Offer); // Wait for user Console.ReadKey(); }
public ActionResult Index(int?searchString) { var viewModel = new ViewModels.DepartmentViewModel(); viewModel.Books = db.Books.Where(b => b.Year > searchString); ViewBag.Title = "Home Page"; //Prototype PrototypeCalling(); //Decorator DecoratorCalling(); //Adapter AdapterCalling(); //Composite CompositeCalling(); //Proxy ProxyCalling(); //Iterator IteratorCalling(); //State StateCalling(); //Command CommandCalling(); //Mediator MediatorCalling(); return(View(viewModel)); void CommandCalling() { Console.WriteLine("Enter Commands (ON/OFF) : "); string input = "ON"; //Console.ReadLine(); Light light = new Light(); ICommand switchUp = new FlipUpCommand(light); ICommand switchDown = new FlipDownCommand(light); CRUDWebApp.DesignPatterns.Switch s = new CRUDWebApp.DesignPatterns.Switch(); if (input == "ON") { s.StoreAndExecute(switchUp); } else if (input == "OFF") { s.StoreAndExecute(switchDown); } else { Debug.WriteLine("Command \"ON\" or \"OFF\" is required."); //Console.log("Command \"ON\" or \"OFF\" is required."); } } void StateCalling() { Steak steak = new Steak("T-Bone"); steak.AddTemp(120); steak.AddTemp(15); steak.AddTemp(15); steak.RemoveTemp(10); steak.RemoveTemp(15); steak.AddTemp(20); steak.AddTemp(20); steak.AddTemp(20); } void IteratorCalling() { // The client code may or may not know about the Concrete Iterator // or Collection classes, depending on the level of indirection you // want to keep in your program. var collection = new WordsCollection(); collection.AddItem("First"); collection.AddItem("Second"); collection.AddItem("Third"); Debug.WriteLine("Straight traversal:"); foreach (var element in collection) { Debug.WriteLine(element); } Debug.WriteLine("\nReverse traversal:"); collection.ReverseDirection(); foreach (var element in collection) { Debug.WriteLine(element); } } void ProxyCalling() { var secureNestProxy = new SecureNestProxy(new RealNest()); secureNestProxy.Access("Stegosaurus"); secureNestProxy.Access("TRex"); } void CompositeCalling() { var plants = new List <IPlant>(); var branchI = new Branch(new List <IPlant>() { new Leaf(), new Leaf() }); var branchII = new Branch(new List <IPlant>() { new Leaf(), new Leaf(), new Leaf(), new Leaf() }); plants.Add(new Branch( new List <IPlant>() { branchI, branchII } )); //branch with two branches plants.Add(new Leaf()); //one leaf plants.Add(new Branch(new List <IPlant>() { new Leaf(), new Leaf(), new Leaf(), new Leaf(), new Leaf() })); //one branch with leafs plants.Add(new Leaf()); //one leaf foreach (IPlant plant in plants) { plant.Eat(); } } void AdapterCalling() { var bagOfPeelableFruit = new List <IPeelable>(); bagOfPeelableFruit.Add(new Orange()); bagOfPeelableFruit.Add(new Banana()); bagOfPeelableFruit.Add(new SkinnableTOPelableAdapter(new Apple())); bagOfPeelableFruit.Add(new SkinnableTOPelableAdapter(new Pear())); foreach (var fruit in bagOfPeelableFruit) { fruit.Peel(); } } void DecoratorCalling() { IPizza pizza = new Pizza(); IPizza cheeseDecorator = new CheeseDecorator(pizza); IPizza tomatoDecorator = new TomatoDecorator(cheeseDecorator); IPizza onionDecorator = new OnionDecorator(tomatoDecorator); Debug.WriteLine(tomatoDecorator.getPizzaType()); } void PrototypeCalling() { Developer dev = new Developer(); dev.Name = "Ann"; dev.Role = "Team Leader"; dev.PreferredLanguage = "C#"; Developer devCopy = (Developer)dev.Clone(); devCopy.Name = "Anna"; //Not mention Role and PreferredLanguage, it will copy above Debug.WriteLine(dev.GetDetails()); Debug.WriteLine(devCopy.GetDetails()); Typist typist = new Typist(); typist.Name = "Beta"; typist.Role = "Typist"; typist.WordsPerMinute = 120; Typist typistCopy = (Typist)typist.Clone(); typistCopy.Name = "Betty"; typistCopy.WordsPerMinute = 115;//Not mention Role, it will copy above Debug.WriteLine(typist.GetDetails()); Debug.WriteLine(typistCopy.GetDetails()); } void MediatorCalling() { ConcessionsMediator mediator = new ConcessionsMediator(); NorthConcessionStand leftKitchen = new NorthConcessionStand(mediator); SouthConcessionStand rightKitchen = new SouthConcessionStand(mediator); mediator.NorthConcessions = leftKitchen; mediator.SouthConcessions = rightKitchen; leftKitchen.Send("Can you send some popcorn?"); rightKitchen.Send("Sure thing, Kenny's on his way."); rightKitchen.Send("Do you have any extra hot dogs? We've had a rush on them over here."); leftKitchen.Send("Just a couple, we'll send Kenny back with them."); } }