예제 #1
0
        static void Main(string[] args)
        {
            // pc case composite part
            Chassis chassis = new Chassis("PC Chassis", 5.0D, 55.00M, 40.00M);

            // add a mother board and graphics card
            MotherBoard board = new MotherBoard("ASUS P5QD", 150.0D, 99.99M, 85.50M);

            chassis.Add(board);
            Card card = new Card("Nvidia GTS 250", 100.0D, 79.99M, 69.99M);

            board.Add(card);

            // and a dvd drive
            OpticalDrive opticalDrive = new OpticalDrive("DVD RW", 10.0D, 21.50M, 15.99M);

            chassis.Add(opticalDrive);

            // pricing visitor
            PricingVisitor visitor = new PricingVisitor();

            chassis.Accept(visitor);

            Console.WriteLine("The net price is: " + visitor.TotalPrice.ToString());
            Console.WriteLine("The discount price is: " + visitor.TotalDiscountPrice.ToString());
        }
예제 #2
0
        // Uses modified code from Chapter 4 "Composite" pattern demo.
        static void Main(string[] args)
        {
            var cabinet = new Cabinet("PC Cabinet", 80);
            var chassis = new Chassis("PC Chassis", 145);

            var m2ssd = new M2SSD("Kingston SSD", 50);
            var ram1  = new RAM("Kingston DDR4 module", 40);
            var ram2  = new RAM("Kingston DDR4 module", 40);

            chassis.Add(m2ssd);
            chassis.Add(ram1);
            chassis.Add(ram2);
            cabinet.Add(chassis);

            var visitor = new PricingVisitor();

            cabinet.Accept(visitor);
            Console.WriteLine($"My dream machine net price is {visitor.TotalPrice} USD.");
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var chassis = new Chassis();

            chassis.Add(new FloppyDisk());
            chassis.Add(new Card("Vodoo FX"));
            chassis.Add(new Bus("AGP"));

            var pricingVisitor = new PricingVisitor();

            chassis.Accept(pricingVisitor);
            Console.WriteLine($"The system build will cost £{pricingVisitor.GetTotal()}");

            var discountedPricingVisitor = new DiscountedPricingVisitor();

            chassis.Accept(discountedPricingVisitor);
            Console.WriteLine($"The discounted system build will cost £{discountedPricingVisitor.GetTotal()}");
        }