Пример #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();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Iron Airport without Air Traffic Controller - without Mediator ;)");

            //Creating flights
            var flightA = new AirbusA320Neo("FLIGHT A", 100);
            var flightB = new Atr72("FLIGHT B", 50);
            var flightC = new Boeing777300("FLIGHT C", 25);

            //All aircraft need to know to each other
            flightA.Acknoledges(flightB);
            flightA.Acknoledges(flightC);

            flightB.Acknoledges(flightA);
            flightB.Acknoledges(flightC);

            flightC.Acknoledges(flightA);
            flightC.Acknoledges(flightB);

            //Flight A wants to land! It needs to do previous checks before landing.
            if (!flightA.ExistAnotherAircraftWithPriorityToLand())
            {
                flightA.Land();
            }

            //If flight B wants to land, it needs to do the same! It needs to consult its internal collection too
            if (!flightB.ExistAnotherAircraftWithPriorityToLand())
            {
                flightB.Land();
            }

            //If flight C wants to land, it needs to do the same! It needs to consult its internal collection too
            if (!flightC.ExistAnotherAircraftWithPriorityToLand())
            {
                flightC.Land();
            }

            //Can you imagine if we have a lot of flights?
        }