static void Main(string[] args) { bool stop = true; Steak account = new Steak("me"); while (stop) { //get an input var input = Console.ReadLine(); if (input == "") { stop = !stop; break; } //make sure we have a number foreach (char c in input) { //if not a number if (Char.IsLetter(c)) { //kill the loop and then the loop stop = false; break; } } //do stuff if (stop) { double inputNum = double.Parse(input); account.AddTemp(inputNum); } } }
static 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); }
static void Main(string[] args) { Steak account = new Steak("T-Bone"); account.AddTemp(120); account.AddTemp(15); account.AddTemp(15); account.RemoveTemp(10); account.RemoveTemp(15); account.AddTemp(20); account.AddTemp(20); account.AddTemp(20); }
private static void Main() { Steak account = new Steak("T-Bone"); // Apply temperature changes. account.AddTemp(120); account.AddTemp(15); account.AddTemp(15); account.RemoveTemp(10); account.RemoveTemp(15); account.AddTemp(20); account.AddTemp(20); account.AddTemp(20); }
public static void State() { //Let's cook a steak! Steak account = new Steak("T-Bone"); // Apply temperature changes account.AddTemp(120); account.AddTemp(15); account.AddTemp(15); account.RemoveTemp(10); //Yes I know cooking doesn't work this way, bear with me. account.RemoveTemp(15); account.AddTemp(20); account.AddTemp(20); account.AddTemp(20); }
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."); } }