//002_2: Function that records the sales //performed on the billing desk public void Sales(ProductStock prod, int howmuch) { Console.WriteLine( "{0} Sold {1} numbers", prod.ProductName, howmuch); prod.ReduceStock(howmuch); }
static void Main(string[] args) { //Client 001: Create Billing Counters Counter billing_counter1 = new Counter("Jupiter"); Counter billing_counter2 = new Counter("Saturn"); //Client 002: Create the Product Stocks ProductStock prod1 = new ProductStock( "Godrej Fridge", 7); ProductStock prod2 = new ProductStock( "Sony CD Player", 6); ProductStock prod3 = new ProductStock( "Sony DVD", 800); //Client 003: Couple the Event with //the Handler through the Delegate. prod1.StockLow += new ProductStock.OnStockLow( billing_counter1.LowStockHandler); prod2.StockLow += new ProductStock.OnStockLow( billing_counter1.LowStockHandler); prod1.StockLow += new ProductStock.OnStockLow( billing_counter2.LowStockHandler); prod2.StockLow += new ProductStock.OnStockLow( billing_counter2.LowStockHandler); //Client 004: Now Let us Start serving //the customers on the Queue on //each counter billing_counter1.Sales(prod1, 1); billing_counter2.Sales(prod1, 2); billing_counter2.Sales(prod3, 70); billing_counter2.Sales(prod2, 1); billing_counter1.Sales(prod2, 3); billing_counter1.Sales(prod3, 5); Console.ReadKey(); }