示例#1
0
        static void Main(string[] args)
        {
            // Create a blue saloon car
            IVehicle myCar = new Saloon(new StandardEngine(1300));

            myCar.Paint(VehicleColour.Blue);
            Console.WriteLine(myCar);

            // Add air-conditioning to the car...
            myCar = new AirConditionedVehicle(myCar);
            Console.WriteLine(myCar);

            // Now add alloy wheels...
            myCar = new AlloyWheeledVehicle(myCar);
            Console.WriteLine(myCar);

            // Now add leather seats...
            myCar = new LeatherSeatedVehicle(myCar);
            Console.WriteLine(myCar);

            // Now add metallic paint...
            myCar = new MetallicPaintedVehicle(myCar);
            Console.WriteLine(myCar);

            // Now add satellite navigation
            myCar = new SatNavVehicle(myCar);
            Console.WriteLine(myCar);

            Console.Read();
        }
        public void CarDecoratorTest()
        {
            //given
            IVehicle car = new Saloon(new StandardEngine(1300));

            car.Paint(VehicleColour.Blue);

            //when
            car = new AlloyWheeledVehicle(car);   //AlloyWheeled
            car = new LeatherSeatedVehicle(car);  //LeatherSeated
            car = new MetalicPaintedVehicle(car); //MetalicPaintedVehicle
            car = new SatNavVehicle(car);         //SateliteNavigation

            System.Console.WriteLine(car);
        }
示例#3
0
    public static void Main()
    {

        // Create a blue saloon car... 
        IVehicle myCar = new Saloon(new StandardEngine(1300));
        myCar.Paint(VehicleColour.Blue);
        Console.WriteLine(myCar);
        // Add air-conditioning to the car...
        myCar = new AirConditionedVehicle(myCar);
        Console.WriteLine(myCar);
        // Now add alloy wheels... 
        myCar = new AlloyWheeledVehicle(myCar);
        Console.WriteLine(myCar);
        // Now add leather seats... 
        myCar = new LeatherSeatedVehicle(myCar); 
        Console.WriteLine(myCar);
        // Now add metallic paint... 
        myCar = new MetallicPaintedVehicle(myCar); 
        Console.WriteLine(myCar);
        // Now add satellite-navigation... 
        myCar = new SatNavVehicle(myCar);
        Console.WriteLine(myCar);

    }