Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Iron Airport with Air Traffic Controller - Power of the Mediator Pattern;)");

            //Mediator ! All interaction between aircraft must be doing through the traffic controller!
            IAirTrafficController trafficController = new IronTrafficController();

            //Declare Colleagues and associate them with the Air Traffic Controller (Mediator)
            AirbusA320Neo flightA = new AirbusA320Neo(trafficController, "Flight A", 2000);
            Atr72         flightB = new Atr72(trafficController, "Flight B", 1500);
            Boeing747     flightC = new Boeing747(trafficController, "Flight C", 1460);
            Boeing777300  flightD = new Boeing777300(trafficController, "Flight D", 1300);

            //flightA wants to land!
            flightA.Land();
            Console.WriteLine();

            //flightB wants to land!
            flightB.Land();
            Console.WriteLine();

            //flight C is moving on 100mts (changing altituded!)
            flightC.ChangeLocation(100);
            Console.WriteLine();

            //flightD wants to land!
            flightD.Land();
            Console.WriteLine();
        }
Exemple #2
0
        public static void Main()
        {
            AbstractPlane plane  = new Boeing747(); // OK
            Boeing747     boeing = new Boeing747(); // OK

            //plane = new AbstractPlane(); // can't do
            plane = boeing;
            //boeing = plane; // can't do implicitly
            boeing = (Boeing747)plane; // can do explicitly - but only if we are sure it is it
            boeing = plane as Boeing747;
        }
Exemple #3
0
        public static void Main()
        {
            // Build a collection of all vehicles that fly
            var airplane   = new Boeing747(200, 250, VehicleColor.Green);
            var helecopter = new Helecoptor(150, 4, VehicleColor.Black);

            List <Aircraft> aircrafts = new List <Aircraft>();

            aircrafts.Add(airplane);
            aircrafts.Add(helecopter);


            // With a single `foreach`, have each vehicle Fly()
            foreach (var aircraft in aircrafts)
            {
                aircraft.Fly(1000);
            }

            // Build a collection of all vehicles that operate on roads
            var ford  = new FordFiesta(12, 5, VehicleColor.Red);
            var jetta = new VWJetta(20, 5, VehicleColor.White);

            List <Car> cars = new List <Car>();

            cars.Add(ford);
            cars.Add(jetta);

            // With a single `foreach`, have each road vehicle Drive()
            foreach (var car in cars)
            {
                car.Drive(50);
            }

            // Build a collection of all vehicles that operate on water
            var skidoo  = new Skidoo(10, 1, VehicleColor.Blue);
            var skipper = new SailBoat(0, 5, VehicleColor.Orange);

            List <Watercraft> watercrafts = new List <Watercraft>();

            watercrafts.Add(skidoo);
            watercrafts.Add(skipper);

            // With a single `foreach`, have each water vehicle Drive()
            foreach (var watercraft in watercrafts)
            {
                watercraft.Drive(5);
            }

            Console.ReadKey();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            var plane       = new Boeing747();
            var wingSuit    = new WingSuit();
            var AirVehicles = new List <IVehicle> {
                plane, wingSuit
            };

            foreach (var item in AirVehicles)
            {
                item.Fly();
            }

            var jeep         = new JeepWrangler();
            var limo         = new Limo();
            var landVehicles = new List <IVehicle> {
                jeep, limo
            };

            foreach (var item in landVehicles)
            {
                item.Drive();
            }

            var seadoo        = new Seadoo();
            var yachty        = new Yachty();
            var waterVehicles = new List <IVehicle> {
                seadoo, yachty
            };

            foreach (var item in waterVehicles)
            {
                item.Drive();
            }

            Console.Read();
            Console.WriteLine("Hello World!");
        }
Exemple #5
0
    public static void Main()
    {
        // create some vehicles using the vehicle classes
        JetSki              StriperJetSki     = new JetSki();
        Motorboat           LargeMotorboat    = new Motorboat(12);
        Motorboat           FastMotorboat     = new Motorboat(8, 6.1);
        Sailboat            LumberingSailBoat = new Sailboat();
        Motorcycle          ZippyMotorcycle   = new Motorcycle();
        SportsCar           LeMansSportsCar   = new SportsCar();
        SportUtilityVehicle Rover             = new SportUtilityVehicle();
        Cessna              TravelingCessna   = new Cessna();
        Boeing747           AirFrance         = new Boeing747();
        HangGlider          SeeingBrazil      = new HangGlider();


        // Build a collection of all vehicles that fly
        List <IVehicleAir> flyingVehicles = new List <IVehicleAir>()
        {
            TravelingCessna,
            AirFrance,
            SeeingBrazil
        };

        // With a single `foreach`, have each vehicle Fly()
        foreach (IVehicleAir vehicle in flyingVehicles)
        {
            vehicle.Fly();
        }


        // Build a collection of all vehicles that operate on roads
        List <IVehicleLand> landVehicles = new List <IVehicleLand>()
        {
            ZippyMotorcycle,
            LeMansSportsCar,
            Rover
        };

        // With a single `foreach`, have each road vehicle Drive()
        foreach (IVehicleLand vehicle in landVehicles)
        {
            vehicle.Drive();
        }


        // Build a collection of all vehicles that operate on water
        List <IWaterDrive> waterVehicles = new List <IWaterDrive>()
        {
            StriperJetSki,
            LumberingSailBoat,
            LargeMotorboat,
            FastMotorboat
        };

        // With a single `foreach`, have each water vehicle Drive()
        foreach (IWaterDrive vehicle in waterVehicles)
        {
            vehicle.Drive();
        }

        // check to see if my overloaded constructor functions for the Motorboat class work
        Console.WriteLine($"LargeMotorboat passenger capacity: {LargeMotorboat.PassengerCapacity}");
        Console.WriteLine($"FastMotorboat Passenger Capacity: {FastMotorboat.PassengerCapacity} Engine Volume: {FastMotorboat.EngineVolume}");
    }