Exemplo n.º 1
0
        public void SubclassesCanModifyExistingBehavior()
        {
            var chico = new Chihuahua("Chico");
            Assert.Equal(FILL_ME_IN, chico.Bark());

            //Note that even if we cast the object back to a dog
            //we still get the Chihuahua's behavior. It truly
            //"is-a" Chihuahua
            Dog dog = chico as Dog;
            Assert.Equal(FILL_ME_IN, dog.Bark());

            var fido = new Dog("Fido");
            Assert.Equal(FILL_ME_IN, fido.Bark());
        }
Exemplo n.º 2
0
        public void SubclassesCanModifyExistingBehavior()
        {
            var chico = new Chihuahua("Chico");

            Assert.Equal("yip", chico.Bark());

            //Note that even if we cast the object back to a dog
            //we still get the Chihuahua's behavior. It truly
            //"is-a" Chihuahua
            Dog dog = chico as Dog;

            Assert.Equal("yip", dog.Bark());

            var fido = new Dog("Fido");

            Assert.Equal("WOOF", fido.Bark());
        }
        public void AboutInheritanceSubclassesCanModifyExistingBehavior()
        {
            var chico = new Chihuahua("Chico");

            Assert.AreEqual(FILL_ME_IN, chico.Bark());

            //Note that even if we cast the object back to a dog
            //we still get the Chihuahua's behavior. It truly
            //"is-a" Chihuahua
            Dog dog = chico as Dog;

            Assert.AreEqual(FILL_ME_IN, dog.Bark());

            var fido = new Dog("Fido");

            Assert.AreEqual(FILL_ME_IN, fido.Bark());
        }
Exemplo n.º 4
0
        public void SubclassesCanModifyExistingBehavior()
        {
            var chico = new Chihuahua("Chico");
            Assert.Equal("yip", chico.Bark());

            //Note that even if we cast the object back to a dog
            //we still get the Chihuahua's behavior. It truly
            //"is-a" Chihuahua
            /*
            What happens to the original Dog class on this cast? Is it overwritten?
            */
            Dog dog = chico as Dog;
            // Why does chico, now as a dog, yip? It should WOOF! since it's now cast as a Dog.
            Assert.Equal("yip", dog.Bark());

            var fido = new Dog("Fido");
            Assert.Equal("WOOF", fido.Bark());
        }
Exemplo n.º 5
0
        public void SubclassesCanModifyExistingBehavior()
        {
            var chico = new Chihuahua("Chico");

            //Assert.AreEqual (FILL_ME_IN, chico.Bark ());
            Assert.AreEqual("bbbbbrip", chico.Bark());

            // Noteu que encara que fem un cast de l'objecte cap a gos
            // encara obtenim el comportament de Chihuahua's behavior.
            // Ja ho diuen que tenen caràcter els petits...
            Dog dog = chico as Dog;

            //Assert.AreEqual(FILL_ME_IN, dog.Bark ());
            Assert.AreEqual("bbbbbrip", dog.Bark());

            var fido = new Dog("Fido");

            //Assert.AreEqual(FILL_ME_IN, fido.Bark ());
            Assert.AreEqual("BUP", fido.Bark());
        }