Ejemplo n.º 1
0
        // Context nesnesi örneklenirken başlangıç durumu belirtilir.
        public VendingMachine()
        {
            // Test için makineye örnek ürünler yüklenir.
            ProductList.Add(new Product {
                Name = "Çikolata K", ListPrice = 10, Count = 50
            });
            ProductList.Add(new Product {
                Name = "Biskuvi Bis", ListPrice = 3.45, Count = 50
            });
            ProductList.Add(new Product {
                Name = "Tuzlu mu tuzlu çıtır", ListPrice = 4.50, Count = 35
            });

            // Makineye ürünleri yükledikten sonra durumunu değiştir
            State = new InitializeState();
        }
Ejemplo n.º 2
0
        public void RequestProduct(string productName, double money)
        {
            Console.WriteLine("Ürün siparişi geldi. {0} için atılan para : {1}", productName, money);
            Product prd = (from p in ProductList
                           where (p.Name == productName && (money >= p.ListPrice && p.Count >= 1))
                           select p).SingleOrDefault <Product>();

            // Eğer talep edilen ürün stokta var ve atılan para yeterli ise
            if (prd != null)
            {
                prd.Count--;
                // Makinenin durumunu değiştir
                State = new PreparingState();
            }
            else
            {
                State = new WaitingState();
            }
        }