static void Main(string[] args) { /* * More info: https://en.wikipedia.org/wiki/Flyweight_pattern * What problems can the Flyweight design pattern solve? [2] * Large numbers of objects should be supported efficiently. * Creating large numbers of objects should be avoided. * * When representing large text documents, for example, creating an object for each character in the document * would result in a huge amount of objects that couldn't be processed efficiently. */ var simpleClient = new ClientObject(); //it'll share the same static FlyWeightPointer Console.WriteLine(simpleClient.Company); var flyWeightPointer = new ReducedMemoryFootprintFlavorFactory(); var minimalflyWeightPointer = new MinimumMemoryFootprint(); var coffeeMaker1 = new CoffeeMaker(flyWeightPointer); var coffeeMaker2 = new CoffeeMaker(flyWeightPointer); var coffeeMaker3 = new CoffeeMaker(flyWeightPointer); var coffeeMaker4 = new CoffeeMaker(flyWeightPointer); coffeeMaker1.MakeCoffee("Pepper?!"); coffeeMaker2.MakeCoffee("Lemon?"); coffeeMaker3.MakeCoffee("Chocolate"); coffeeMaker4.MakeCoffee("Spider"); }
static void Main(string[] args) { CoffeeMaker coffeeMaker = new CoffeeMaker(1000, 500, 700, 250); Console.WriteLine($"What kind of coffee do you make?\n1:Late\n2:Americano\n3:Capuchino\n4:Expresso"); int b = Convert.ToInt32(Console.ReadLine()); if (b == 1) { coffeeMaker.MakeCoffee(TypeOfCoffee.Late); } else if (b == 2) { coffeeMaker.MakeCoffee(TypeOfCoffee.Americano); } else if (b == 3) { coffeeMaker.MakeCoffee(TypeOfCoffee.Capuchino); } else if (b == 4) { coffeeMaker.MakeCoffee(TypeOfCoffee.Expresso); } else { Console.WriteLine($"Wrong expression"); coffeeMaker.counter -= 1; } if (coffeeMaker.counter == 1) { Console.WriteLine($"How much sugar to add?"); coffeeMaker.Sugar(); if (coffeeMaker.counter == 1) { Console.WriteLine($"Your coffee is ready.You are {coffeeMaker.price} UAH"); } } }
public void ExpressMaker_makes_espresso() { var grinderStub = new Mock <IBeanGrinder> (); grinderStub.Setup(g => g.Grind()).Returns(new Beans(true)); var boilerFake = new FakeWaterBoiler(); var portaFilterMock = new Mock <IPortaFilter>(); var expressoMaker = new CoffeeMaker( grinderStub.Object, boilerFake, portaFilterMock.Object ); var cup = CoffeeMaker.MakeCoffee(); portaFilterMock.Verify(p => p.Load(It.Is <IBeans>(b => b.Ground))); portaFilterMock.Verify(p => p.Tamp(), "PortaFilter was not tamped"); portaFilterMock.Verify(p => p.Push(It.Is <IWater>(w => w.Temprature > 90))); portaFilterMock.Verify(p => p.Receive(It.IsAny <Cup>())); }
public void StartDay() { //?.XXX means if _coffeeMaker object is not null, invoke method CoffeeMaker?.MakeCoffee(); }