Hacker News new | past | comments | ask | show | jobs | submit login
Command Design Pattern Explained with C (dev.to)
1 point by Delawhere on April 8, 2020 | hide | past | favorite | 1 comment



class Program { static void Main(string[] args) { DineChef dineChef = new DineChef(); dineChef.SetOrderCommand(1); /* Insert Order / dineChef.SetMenuItem(new MenuItem() { TableNumber = 1, Item = "Super Mega Burger", Quantity = 1, Tags = new List() { new Tag() { TagName = "Jalapenos,"}, new Tag() { TagName = " Cheese," }, new Tag() { TagName = " Tomato" }} }); dineChef.ExecuteCommand();

        dineChef.SetOrderCommand(1); /* Insert Order */
        dineChef.SetMenuItem(new MenuItem()
        {
            TableNumber = 1, Item = "Cheese Sandwich", Quantity = 1,
            Tags = new List(){ new Tag() { TagName = "Spicy Mayo,"} }
        });
        dineChef.ExecuteCommand();
        dineChef.ShowCurrentOrder();

        dineChef.SetOrderCommand(3); /* Remove the Cheese Sandwich */
        dineChef.SetMenuItem(new MenuItem()
        {
            TableNumber = 1, Item = "Cheese Sandwich"
        });
        dineChef.ExecuteCommand();
        dineChef.ShowCurrentOrder();

        dineChef.SetOrderCommand(2);/* Modify Order */
        dineChef.SetMenuItem(new MenuItem()
        {
            TableNumber = 1, Item = "Super Mega Burger", Quantity = 1,
            Tags = new List() { new Tag() { TagName = "Jalapenos,"}, new Tag() { TagName = " Cheese" }}
        });
        dineChef.ExecuteCommand();
        dineChef.ShowCurrentOrder();
        Console.ReadKey();
    }
}




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: