static void Main()
    {
        // No adapter
        Console.WriteLine("Experiment 1: test the aircraft engine");
        IAircraft aircraft = new Aircraft();

        aircraft.TakeOff();
        if (aircraft.Airborne)
        {
            Console.WriteLine("The aircraft engine is fine, flying at " + aircraft.Height + "metres");
        }

        // Classic usage of an Adapter
        Console.WriteLine("\nExperiment 2: Use the engine in the SeaBird");
        IAircraft seabird = new Seabird();

        seabird.TakeOff(); // and automatically increases speed
        Console.WriteLine("The SeaBird took off");

        // Two-way adapter: using seacraft instructions on an IAircraft object
        // (where they are not in the IAricraft interface)
        Console.WriteLine("\nExperiment 3: Increase the speed of the Seabird:");
        (seabird as ISeacraft).IncreaseRevs();
        (seabird as ISeacraft).IncreaseRevs();
        if (seabird.Airborne)
        {
            Console.WriteLine("Seabird flying at height " + seabird.Height +
                              " metres and speed " + (seabird as ISeacraft).Speed + " knots");
        }
        Console.WriteLine("Experiments successful; the Seabird flies!");
        Console.ReadKey();
    }
Пример #2
0
    static void Main()
    {
        // No adapter
        Console.WriteLine("Experiment 1: test the aircraft engine:");
        IAircraft aircraft = new Aircraft();
        IAircraft seabird  = new Seabird();

        (seabird as ISeacraft).IncreaseRevs();
        (seabird as ISeacraft).IncreaseRevs();
        (seabird as ISeacraft).IncreaseRevs();
        (seabird as ISeacraft).IncreaseRevs();
        (seabird as ISeacraft).IncreaseRevs();


        Console.WriteLine("\nExperiment 2: Increase the speed of the Seabird, Aircraft engine takeoff");
        (seabird as ISeacraft).IncreaseRevs();
        (seabird as ISeacraft).IncreaseRevs();
        seabird.RaiseNose();
        aircraft.TakeOff();
        if (aircraft.Airborne)
        {
            Console.WriteLine("The aircraft engine is fine, flying at " + aircraft.Height + " metres");
        }

        Console.WriteLine("\nExperiment 3: Increase height of the Seabird");
        seabird.IncreaseHeight();
        if (seabird.Airborne)
        {
            Console.WriteLine("Seabird flying at height " + seabird.Height +
                              " metres and speed " + (seabird as ISeacraft).Speed + " knots");
        }
        seabird.IncreaseHeight();
        if (seabird.Airborne)
        {
            Console.WriteLine("Seabird flying at height " + seabird.Height +
                              " metres and speed " + (seabird as ISeacraft).Speed + " knots");
        }
        seabird.IncreaseHeight();
        if (seabird.Airborne)
        {
            Console.WriteLine("Seabird flying at height " + seabird.Height +
                              " metres and speed " + (seabird as ISeacraft).Speed + " knots");
        }


        // Two-way adapter: using seacraft instructions on an IAircraft object
        // (where they are not in the IAricraft interface)
        Console.WriteLine("\nExperiment 4: Prepare for landing");
        seabird.LowerNose();
        while (seabird.Airborne)
        {
            seabird.DecreaseHeight();
        }

        Console.WriteLine("Seabird is at height " + seabird.Height +
                          " metres and speed " + (seabird as ISeacraft).Speed + " knots. Landed Successfully!");
        Console.ReadKey();
    }
Пример #3
0
        static void Main(string[] args)
        {
            //Classic usage of an adapter
            Console.WriteLine("\nExperiment 1.1: Use the engine in the Seabird:");
            IAircraft seabird = new Seabird();

            seabird.TakeOff(); //And automatically increases speed
            Console.WriteLine("The Seabird took off");

            //Two-way adapter: using seacraft instructions on an IAircraft object (where they are not in the IAircraft interface)
            Console.WriteLine("\nExperiment 1.2: Increase the speed of the Seabird:");
            (seabird as ISeacraft).IncreaseRevs();
            (seabird as ISeacraft).IncreaseRevs();
            if (seabird.Airborne)
            {
                Console.WriteLine("Seabird flying at height " + seabird.Height +
                                  " meters and speed " + (seabird as ISeacraft).Speed + " knots");
            }
            Console.WriteLine("Experiments successful; the Seabird flies!");

            Console.WriteLine("\nExperiment 2.1: Increase the speed of the SeabirdAircraft:");
            ISeacraft seabird2 = new SeabirdAircraft();

            seabird2.IncreaseRevs();
            seabird2.IncreaseRevs();
            Console.WriteLine($"SeabirdAircraft has speed {seabird2.Speed} knots");

            Console.WriteLine("\nExperiment 2.2: Use the engine in the SeabirdAircraft");
            (seabird2 as IAircraft).TakeOff();
            Console.WriteLine("The SeabirdAircraft took off");
            if ((seabird2 as IAircraft).Airborne)
            {
                Console.WriteLine("SeabirdAircraft flying at height " + (seabird2 as IAircraft).Height +
                                  " meters and speed " + seabird2.Speed + " knots");
            }
            Console.WriteLine("Experiments successful; the SeabirdAircraft flies!");
        }
Пример #4
0
 public void Setup()
 {
     seabird = new Seabird();
 }
 private static IAircraft TestSeaBirdEngine()
 {
     // Classic usage of an Adapter
     Console.WriteLine("\nExperiment 2: Use the engine in the SeaBird");
     IAircraft seabird = new Seabird();
     seabird.TakeOff(); // and automatically increases speed
     Console.WriteLine("The SeaBird took off");
     return seabird;
 }
    static void Main (  ) {
      // No adapter
      Console.WriteLine("Experiment 1: test the aircraft engine");
      IAircraft aircraft = new Aircraft(  );
      aircraft.TakeOff(  );
      if (aircraft.Airborne) Console.WriteLine(
           "The aircraft engine is fine, flying at "
           +aircraft.Height+"meters");

      // Classic usage of an adapter
      Console.WriteLine("\nExperiment 2: Use the engine in the Seabird");
      IAircraft seabird = new Seabird(  );
      seabird.TakeOff(  ); // And automatically increases speed
      Console.WriteLine("The Seabird took off");

      // Two-way adapter: using seacraft instructions on an IAircraft object
      // (where they are not in the IAircraft interface)
      Console.WriteLine("\nExperiment 3: Increase the speed of the Seabird:");
      (seabird as ISeacraft).IncreaseRevs(  );
      (seabird as ISeacraft).IncreaseRevs(  );
      if (seabird.Airborne)
        Console.WriteLine("Seabird flying at height "+ seabird.Height +
            " meters and speed "+(seabird as ISeacraft).Speed + " knots");
      Console.WriteLine("Experiments successful; the Seabird flies!");
     }
Пример #7
0
        //przy dodaniu dziedziczenia seacraft : aircraft
        public void SeabirdIsAircraft()
        {
            Seabird seabird = new Seabird();

            Assert.IsTrue(seabird is Aircraft);
        }
Пример #8
0
            public static void TwoAdapter()
            {
                IAircraft aircraft = new AirCraft();
                aircraft.TakeOff();
                if (aircraft.IsAirBrone)
                {
                    Console.WriteLine("Aircraft engine is fine, fly at the height of "+aircraft.Height + " meters");
                }
                //ISeaCraft seaCraft = new SeaCraft();
                IAircraft seabird = new Seabird();
                seabird.TakeOff();
                ((ISeaCraft)seabird).IncreaseRev();
                ((ISeaCraft)seabird).IncreaseRev();
                ((ISeaCraft)seabird).IncreaseRev();

                if (seabird.IsAirBrone)
                {
                    Console.WriteLine("Seabird flying at height of " + seabird.Height + " meters and speed of " + ((ISeaCraft)seabird).Speed + " knots");

                }


            }