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"); }
public static void Run() { // Builder Pattern // - a director object which enforces a specific process uses builders // - these builders implement the builder abstraction that the director depends on // - these builders enable variations in details of each step in the process enforced by the director var coffeeMaker = new CoffeeMaker(); var americano = new AmericanoBuilder(); var latte = new LatteBuilder(); var flavoredlatte = new FlavoredLatteBuilder(); var ventiIcedAmericanoOrder = new DrinkOrder(iced: true, DrinkSize.Venti, americano); var tallIcedLatteOrder = new DrinkOrder(iced: true, DrinkSize.Tall, latte); var grandeHotFlavoredLatteOrder = new DrinkOrder(iced: false, DrinkSize.Grande, flavoredlatte); coffeeMaker.AcceptOrder(ventiIcedAmericanoOrder); coffeeMaker.BuildCoffee(); var ventiIcedAmericano = coffeeMaker.GetCoffee(); Console.WriteLine(ventiIcedAmericano.Description); coffeeMaker.AcceptOrder(tallIcedLatteOrder); coffeeMaker.BuildCoffee(); var tallIcedLatte = coffeeMaker.GetCoffee(); Console.WriteLine(tallIcedLatte.Description); coffeeMaker.AcceptOrder(grandeHotFlavoredLatteOrder); coffeeMaker.BuildCoffee(); var grandeHotFlavoredLatte = coffeeMaker.GetCoffee(); Console.WriteLine(grandeHotFlavoredLatte.Description); }
private async void ExecuteCoffeePurchase() { Console.WriteLine($"CoffeeMaker: {CoffeeMaker}, Program: {SelectedCoffeeProgram}, NumberOfCoffees: {NumberOfCoffees}"); Console.WriteLine($"Sender: {_web3.TransactionManager.Account.Address}"); if (CoffeeMaker.IsNullOrEmpty() || !CoffeeMaker.IsValidEthereumAddress() || SelectedCoffeeProgram < 0 || NumberOfCoffees <= 0) { Console.WriteLine("Invalid input for transaction. Aborting."); return; } var costs = CoffeePrograms[SelectedCoffeeProgram].Price * NumberOfCoffees; if ((await _coffeeEconomyService.GetTokensAsync(_account.Address)) < costs) { Console.WriteLine("Not enough coffee tokens to buy this much coffee."); return; } IsBusy = true; var transactionId = await _coffeeEconomyService.BuyCoffeeAsync(CoffeeMaker, SelectedCoffeeProgram, NumberOfCoffees); Console.WriteLine($"TransactionId: {transactionId}"); CoffeeMaker = null; ResetLoadedVariables(); IsBusy = false; }
static void Main(string[] args) { CoffeeMaker coffee = new CoffeeMaker(new BlackCoffee()); DoAction(coffee); coffee.MyCoffee = new NessCoffee(); DoAction(coffee); }
public void Interrupt_BrewCiffee_WarmerEmpty() { CoffeeMaker maker = new CoffeeMaker(); Input input = new WarmerEmpty(); Assert.IsInstanceOfType(maker.coffeeMaker, typeof(BrewCoffee)); maker.change(input); Assert.IsInstanceOfType(maker.coffeeMaker, typeof(Interrupt)); }
public void ReadyCoffee_BoilerEmpty() { CoffeeMaker maker = new CoffeeMaker(); Input input = new BoilerEmpty(); Assert.IsInstanceOfType(maker.coffeeMaker, typeof(BrewCoffee)); maker.change(input); Assert.IsInstanceOfType(maker.coffeeMaker, typeof(ReadyCoffee)); }
void Explode(CoffeeMaker coffeemaker) { // TODO: play die animation & sound if (HitEnemy != null) { HitEnemy(coffeemaker); } Destroy(gameObject); }
public void AddOrUpdateCoffeeMakerDetails(CoffeeMaker coffeeMaker) { var knownCoffeeMakers = Settings.Current.KnownCoffeeMakers; knownCoffeeMakers.RemoveAll(c => c.Address == coffeeMaker.Address); knownCoffeeMakers.Add(coffeeMaker); Settings.Current.KnownCoffeeMakers = knownCoffeeMakers; }
private async void LoadCoffeeMakerPrograms() { if (CoffeeMaker.IsNullOrEmpty() || !CoffeeMaker.IsValidEthereumAddress()) { return; } try { var details = await _coffeeEconomyService.GetCoffeeMakerDataAsync(CoffeeMaker); if (details == null) { return; } CoffeeMakerDetails = details; var programs = await _coffeeEconomyService.GetCoffeeMakerProgramCountAsync(CoffeeMaker); Console.WriteLine($"Found {programs} coffee programs!"); if (programs > 0) { var list = new List <CoffeeMakerProgram>(); for (int i = 0; i < programs; i++) { var program = await _coffeeEconomyService.GetCoffeeMakerProgramDetailsAsync(CoffeeMaker, i); list.Add(program); Console.WriteLine($"Coffee program: {program.Name}, Price: {program.Price}"); } CoffeePrograms = list; SelectedCoffeeProgram = 0; // add the discovered coffee maker to our list of known coffee makers but only if it is a valid one var extendedCoffeeMakerDetails = new Models.CoffeeMaker { Address = CoffeeMaker, OwenerAddress = details.OwenerAddress, Name = details.Name, Department = details.Department, DescriptiveLocation = details.DescriptiveLocation, Latitude = details.Latitude, Longitude = details.Longitude, MachineInfo = details.MachineInfo, MachineType = details.MachineType, }; _coffeeMakerStorageService.AddOrUpdateCoffeeMakerDetails(extendedCoffeeMakerDetails); } } catch (Exception) { // reset our view data ResetLoadedVariables(); } }
public static void Main() { //new 연산자로 객체를 생성함. CoffeeMaker cm = new CoffeeMaker(); //객체를 통한 메소드 호출 cm.onState = true; cm.StartCoffeMaker(); }
public void BrewCoffee_after_Interruption_WarmerNotEmpty() { ICoffeeMaker makerType = new Interrupt(); CoffeeMaker maker = new CoffeeMaker(makerType); Input input = new WarmerNotEmpty(); Assert.IsInstanceOfType(maker.coffeeMaker, typeof(Interrupt)); maker.change(input); Assert.IsInstanceOfType(maker.coffeeMaker, typeof(BrewCoffee)); }
public void PourCoffee_when_Ready_warmerEmpty() { ICoffeeMaker makerType = new ReadyCoffee(); CoffeeMaker maker = new CoffeeMaker(makerType); Input input = new WarmerEmpty(); Assert.IsInstanceOfType(maker.coffeeMaker, typeof(ReadyCoffee)); maker.change(input); Assert.IsInstanceOfType(maker.coffeeMaker, typeof(PourCoffee)); }
public void Readycoffee_afterPour_warmerNotEmpty() { ICoffeeMaker makerType = new PourCoffee(); CoffeeMaker maker = new CoffeeMaker(makerType); Input input = new WarmerNotEmpty(); Assert.IsInstanceOfType(maker.coffeeMaker, typeof(PourCoffee)); maker.change(input); Assert.IsInstanceOfType(maker.coffeeMaker, typeof(ReadyCoffee)); }
public void MakeDrink_CoffeeWithMilk_ReturnsCorrectString() // Testa metoden för kaffe med mjölk. Uppgift 2(b) { // Arrange var coffeemaker = new CoffeeMaker(); var coffeeWithMilk = new Coffee(true, false)); // Act var resultString = coffeemaker.MakeDrink(coffeeWithMilk); // Assert StringAssert.Contains("Coffee with milk", resultString); }
static void Main(string[] args) { IBeverage cupOfJuice = new Beverage("Apple Juice"); cupOfJuice = cupOfJuice.AddIngredient(new (20, "water")) .AddIngredient(new (5, "apple")) .ServeBeverage(); IBeverage cupOfCoffee = new Beverage("Coffee") .AddIngredient(new (10, "Water")) .AddIngredient(new (5, "beans")) .AddIngredient(new (5, "milk")) .ServeBeverage(); IBeverage starbucksCoffee = new Beverage("Starbucks sugar in water") .AddIngredient(new (10, "Water")) .AddIngredient(new (5, "beans")) .AddIngredient(new (5, "milk")) .AddIngredient(new (500, "sugar")) .ServeBeverage(); CoffeeMaker newCoffeMaker = new CoffeeMaker(); Beverage newCoffee = newCoffeMaker .StartBrewingCoffee() .AddWater() .AddBeans() .AddALittleBitOfMilk() .FinishBrewing(); JuicePress newJuicePress = new JuicePress(); Beverage newGlassOfJuice = newJuicePress .StartMixingJuice() .AddApple() .AddOrange() .AddALittleBitOfWater() .AddIce() .FinishMixing(); MilkshakeMachine newMilkshakeMachine = new MilkshakeMachine(); Beverage milkshakeMaster5000 = newMilkshakeMachine .Shaker() .AddIceCream("Chocolate") .AddSyrup("Chocolate") .AddSprinkles("Chocolate") .FinishShaking(); // Test push this /* pseudo-code * Espresso espresso = new Espresso().AddWater(20).AddBeans(b => b.AmountInG = 5 && b.Sort = CoffeSorts.Robusta).ToBravage(); * //espresso is type of Espresso * * Latte latte = new Espresso().AddWater(20).AddBeans(b => b.AmountInG = 7 && b.Sort = CoffeSorts.Robusta).AddMilk().ToBravage(); * //latte is type of Latte */ }
public void Test_MakeCoffeeWithMilk_Succeeds() { // Arrange var coffemaker = new CoffeeMaker(); // Act string res = coffemaker.MakeDrink(new Coffee(true, false)); // Assert StringAssert.Contains("Coffee with milk", res); }
public void When_Adding_Milk_To_Coffee_Expect_Milk_In_Ingredients_List() { var coffeMachine = new CoffeeMaker(); var beverage = coffeMachine .StartBrewingCoffee() .AddWater() .AddBeans() .AddALotOfMilk() .FinishBrewing(); Assert.Equal("milk", beverage.Ingredients[2].Type.ToLower()); }
static void Main() { Console.WriteLine("Какой коффе: americano, latte, espresso, capucino"); string coffee = Console.ReadLine().ToLower(); Console.WriteLine(); CoffeeMaker coffeeMaker = new CoffeeMaker(); coffeeMaker.MakeCoffe(coffee); }
void OnTriggerEnter2D(Collider2D collider) { if (collider.transform.parent == null) { return; } CoffeeMaker coffeeMaker = collider.transform.parent.GetComponent <CoffeeMaker>(); if (coffeeMaker != null) { Explode(coffeeMaker); } }
public void When_Using_CoffeeMaker_Expect_Coffee() { //Pseudo code var coffeMachine = new CoffeeMaker(); var beverage = coffeMachine .StartBrewingCoffee() .AddWater() .AddBeans() .FinishBrewing(); // Assert Assert.Equal("Coffee", beverage.CupType); }
static void Main(string[] args) { var makeCoffeeCommand = new Command("Make Coffee", 2, new Dictionary <string, int> { ["beans"] = 2, ["water"] = 1 }); var coffeeMaker = new CoffeeMaker("Kafe", 100, 10, new HashSet <Command> { makeCoffeeCommand }, 10, 10); Console.WriteLine(coffeeMaker.ExecuteCommand("Make Coffee", 10)); Console.WriteLine(coffeeMaker.GetInfo()); }
public void BatchNewPerformanceTest() { var st = Stopwatch.StartNew(); for (var i = 0; i < 500000; i++) { var coffeeMaker = new CoffeeMaker(new FrenchCoffee(), null); GC.KeepAlive(coffeeMaker); } st.Stop(); Trace.WriteLine($"Ellaped: {st.ElapsedMilliseconds}"); }
static void CoffeeTest() { //MrCoffee lifesaver = new MrCoffee(); CoffeeMaker lifesaver = new CoffeeMaker(); lifesaver.AddGrains(5.0); lifesaver.AddWater(12); lifesaver.InsertFilter(); lifesaver.Make(); QuickMath qm = new QuickMath(5, 6); int x = new QuickMath(6, 7).Add(); x = QuickMaths.add(5, 6); //int k = lifesaver.AddGrains(4000000); }
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(); }
private void AttackEnemy(CoffeeMaker coffeemaker, float attackDamage) { coffeemaker.TakeDamage(attackDamage); }
public void Setup() { m_Coffeemaker = new CoffeeMaker(); }
public static void DoAction(CoffeeMaker coffee) { coffee.MakeCoffe(); Console.WriteLine("Details about the coffee: " + coffee.GetDetails()); }