static void Main(string[] args)
        {
            //S - The QuadRotor class is only responsible for itself / it's own methods and properties
            //O - Instead of modifying the Drone class we extend it into QuadRotor Drone
            //L - We override the parent class to get new functionality in the FlightSpeed method
            //I - These objects do not use any interfaces they do not need (currently none infact)
            //D - the QuadRotor Drone only depends on the abstract parent class, Drone() - not vice versa



            Console.WriteLine("Welcome to the QuadRotor Drone class!");


            Console.WriteLine("\nHow far did your drone go?\n");

            int distance = Validator.GetNumber("Please enter first distance in feet (1 - 1000)", 1, 1000);

            int flyTime = Validator.GetNumber("Please enter first fly time in minutes (1 - 1000)", 1, 1000);

            int distance2 = Validator.GetNumber("Please enter second distance in feet (1 - 1000)", 1, 1000);

            int flyTime2 = Validator.GetNumber("Please enter second fly time in minutes (1 - 1000)", 1, 1000);

            QuadrotorDrone newDrone = new QuadrotorDrone(flyTime, distance, flyTime2, distance2);

            Console.WriteLine("Your (average) speed is {0} feet per minute!", newDrone.FlightSpeed());

            Console.ReadKey(true);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            /* SOLID principles in action:
             *  Single Responsibility - the method FlightSpeed only does one thing: calculate speed as (distance/time)
             *  Open/Closed - abstract parent class allows the subclass to get added functionality without any changes to the parent class
             *  Liskov Substitution - a QuadrotorDrone object could be used in place of a Drone object without any other changes to the code
             *      (the fact that Drone is abstract notwithstanding)
             *  Interface Segregation - code is split into multiple small parts, only one of which (the QuadrotorDrone class [and Main I guess])
             *      the user actually interacts with; there isn't an interface used here, but if it were, it would also be used this way
             *  Dependency Inversion - objects depend on the abstraction of Drone in order to function,
             *      instead of a direct interaction between two concrete objects
             */

            var    test      = new QuadrotorDrone(3, 120);
            double speedTest = test.FlightSpeed(test.TotalFlyTime, test.TotalDistance);

            Console.WriteLine($"The speed of test 1 was {speedTest} ft/min.");

            var    test2      = new QuadrotorDrone();
            double speedTest2 = test2.FlightSpeed(test2.TotalFlyTime, test2.TotalDistance);

            Console.WriteLine($"The speed of test 2 was {speedTest2} ft/min.");

            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Drone d = new QuadrotorDrone(5, 15);

            Console.WriteLine(d.FlightSpeed());
        }