Ejemplo n.º 1
0
        // "[..] dynamic dispatch is the process of selecting which implementation of a polymorphic operation (method or function) to call at runtime [..]" http://en.wikipedia.org/wiki/Dynamic_dispatch
        public static void Start()
        {
            Console.WriteLine("\nSingleDispatch\n");

            // Single Dispatch
            IEntityInSpace a = new SpaceShip();
            IEntityInSpace b = new Asteroid();

            // C# calls the correct method based on the type of the object before the dot even though the concrete type is unknown during compile time
            Console.WriteLine(a.Describe());
            Console.WriteLine(b.Describe());
        }
Ejemplo n.º 2
0
        // "[..] dynamic dispatch is the process of selecting which implementation of a polymorphic operation (method or function) to call at runtime [..]" http://en.wikipedia.org/wiki/Dynamic_dispatch
        static public void Start()
        {
            Console.WriteLine("\nSingleDispatch\n");

            // Single Dispatch
            IEntityInSpace a = new SpaceShip();
            IEntityInSpace b = new Asteroid();

            // C# calls the correct method based on the type of the object before the dot even though the concrete type is unknown during compile time
            Console.WriteLine(a.Describe());
            Console.WriteLine(b.Describe());
        }