Exemplo n.º 1
0
        static void Main(string[] args)
        {
            {
                MovableObject obj = new MovableObject();

                // left
                ILeft objLeft = obj;
                objLeft.Move();

                // right
                IRight objRight = obj;
                objRight.Move();
            }

            Console.WriteLine("-------------");
            {
                // implementing both
                IMoving moving = new MovingObject();
                //moving.Move(); // does not compile, ambiguous call

                // left
                ILeft movingLeft = moving;
                movingLeft.Move();

                // right
                IRight movingRight = moving;
                movingRight.Move();
            }
            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            MovableObject obj = new MovableObject();

            // left
            ILeft objLeft = obj;

            objLeft.Move();

            // right
            IRight objRight = obj;

            objRight.Move();

            // implementing both
            IMoving moving = new MovingObject();
            // smoving.Move(); // does not compile, ambiguous call

            // left
            ILeft movingLeft = moving;

            movingLeft.Move();

            // right
            IRight movingRight = moving;

            movingRight.Move();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var moveableObj = new MoveableOject();
            //moveableObj.Move();
            ILeft left = moveableObj;

            left.Move();

            ((ILeft)moveableObj).Move();
            ((IRight)moveableObj).Move();
        }