Esempio n. 1
0
        public static void Driver()
        {
            IBM ibm = new IBM("IBM", 25.5);

            Investor investorOne = new Investor("Prem", new List <Stock>()
            {
                ibm
            });

            //Investor investorTwo = new Investor("Pallavi", new List<Stock>() { ibm });

            ibm.Attach(investorOne);
            //ibm.Attach(investorTwo);

            ibm.Price = 25.1;
            ibm.Price = 25.6;
            ibm.Price = 55.5;
            ibm.Price = 55.5;
            ibm.Price = 59.5;
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
#if singleton
            //Singleton Pattern
            Player p1 = Player.Instance;
            Console.WriteLine($"Name = {p1.Name}, Lvl = {p1.Level}");
#endif

#if factory
            //Factory Pattern
            Gameboard gb = new Gameboard();
            gb.PlayArea(1);
#endif

#if strategy
            //Strategy Pattern
            ShoppingCart cart1 = new ShoppingCart(new TenPercentDiscountStrategy());
            cart1.CustomerName = "John Doe";
            cart1.BillAmount   = 100;
            Console.WriteLine($"Customer = {cart1.CustomerName}, Bal = ${cart1.GetFinalBill()}");

            ShoppingCart cart2 = new ShoppingCart(new FiftyPercentDiscountStrategy());
            cart2.CustomerName = "Jack Wilson";
            cart2.BillAmount   = 200;
            Console.WriteLine($"Customer = {cart2.CustomerName}, Bal = ${cart2.GetFinalBill()}");
#endif

#if chainofresponsibility
            //Chain of responsibility
            Material material = new Material
            {
                MaterialID    = Guid.NewGuid(),
                Name          = "Pebbles",
                PartNumber    = "234",
                DrawingNumber = "345",
                Budget        = 100000
            };

            Approver engineer   = new EngineeringApprover();
            Approver purchasing = new PurchasingApprover();
            Approver finance    = new FinanceApprover();

            engineer.SetNextApprover(purchasing);
            purchasing.SetNextApprover(finance);

            string reason = "";
            if (engineer.ApproveMaterial(material, ref reason))
            {
                Console.WriteLine($"Approved. {reason}");
            }
            else
            {
                Console.WriteLine($"Disapproved. Reason: {reason}");
            }
#endif

#if observer
            Amazon   amzn = new Amazon(1752.12);
            Investor joe  = new Investor("Joe");
            joe.BuyStock(amzn);

            amzn.PriceChanged(1800.12);
#endif

#if adapter
            CustomerDTO customerDTO = new CustomerDTO
            {
                ID         = 1,
                FirstName  = "John",
                LastName   = "Doe",
                Address    = "123 Main St",
                City       = "Portland",
                State      = "OR",
                PostalCode = "12345"
            };

            ICustomerList customerList = new CustomerAdapter();
            customerList.AddCustomer(customerDTO);

            List <Customer> c = customerList.GetCustomers();
#endif

#if COI
#endif
            //Do not delete
            Console.ReadKey();
        }