示例#1
0
        public void SubclassesInheritBehaviorFromParentClass()
        {
            var chico = new Chihuahua("Chico");

            //Assert.AreEqual (FILL_ME_IN, chico.Name);
            Assert.AreEqual("Chico", chico.Name);
        }
示例#2
0
        public void SubclassesInheritBehaviorFromParentClass()
        {
            var chico = new Chihuahua("Chico");
            Dog dog   = chico as Dog;

            Assert.Equal(dog.Name, chico.Name);
        }
示例#3
0
        public void SubclassesAddNewBehavior()
        {
            var chico = new Chihuahua("Chico");
            Assert.Equal("Happy", chico.Wag());

            //We can search the public methods of an object
            //instance like this:
            Assert.NotNull(chico.GetType().GetMethod("Wag"));

            //So we can show that the Wag method isn't on Dog.
            //Proving you can't wag the dog.
            var dog = new Dog("Fluffy");
            Assert.Null(dog.GetType().GetMethod("Wag"));
        }
        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());
        }
示例#5
0
        public void SubclassesAddNewBehavior()
        {
            var chico = new Chihuahua("Chico");

            Assert.Equal("Happy", chico.Wag());

            //We can search the public methods of an object
            //instance like this:
            Assert.NotNull(chico.GetType().GetMethod("Wag"));

            //So we can show that the Wag method isn't on Dog.
            //Proving you can't wag the dog.
            var dog = new Dog("Fluffy");

            Assert.Null(dog.GetType().GetMethod("Wag"));
        }
示例#6
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());
        }
示例#7
0
        public void SubclassesAddNewBehavior()
        {
            var chico = new Chihuahua("Chico");

            //Assert.AreEqual (FILL_ME_IN, chico.Wag ());
            Assert.AreEqual("Estic content i moc la cua!", chico.Wag());

            // Podem buscar els mètodes públics de la instància
            // d'un objecte de la següent manera:
            Assert.IsNotNull(chico.GetType().GetMethod("Wag"));

            // D'aquesta manera podem constatar que el mètode "Wag"
            // no es troba a gos. Proveu a cridar "Wag" d'un gos...
            var dog = new Dog("Fluffy");

            Assert.IsNull(dog.GetType().GetMethod("Wag"));
        }
        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());
        }
示例#9
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());
        }
示例#10
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());
        }
示例#11
0
        static void Main(string[] args)
        {
            // Dog bingo = new Dog(true, "Bingo", 5);
            // bingo.Speak();
            Chihuahua hero = new Chihuahua(true, "Hero", 7, false);

            hero.Speak();
            GreatDane scooby = new GreatDane(true, "Scooby-Doo", 30, false);

            scooby.Speak();


            List <Dog> dogs = new List <Dog>();

            dogs.Add(hero);
            dogs.Add(scooby);

            dogs.ForEach(d =>
            {
                d.Speak();
                d.Eat("chewToy");
            });
        }
示例#12
0
        static void Main(string[] args)
        {
            var utahraptor  = new Utahraptor();
            var triceratops = new Triceratops();
            var stygimoloch = new Stygimoloch();
            var stegosaurus = new Stegosaurus();
            var dinos       = new DinoBase[] { utahraptor, triceratops, stegosaurus, stygimoloch };

            var boxer     = new Boxer();
            var rotweiler = new Rotweiler();
            var chihuahua = new Chihuahua();
            var dogs      = new DogBase[] { boxer, rotweiler, chihuahua };

            Console.WriteLine("Do You want to learn about dogs or dinosaurs? (dog/dino)");

            string answer = Console.ReadLine();

            if (answer == "dino")
            {
                foreach (var dino in dinos)
                {
                    dino.PrintDinos();
                    dino.Carnivore();
                    Console.ReadLine();
                }
            }
            else if (answer == "dog")
            {
                foreach (var dog in dogs)
                {
                    dog.PrintDogs();
                    dog.Loyalty();
                    Console.ReadLine();
                }
            }
        }
        static void Main(string[] args)
        {
            Console.Clear();
            //   cannot instatiate an abstract class
            //   Dog bingo = new Dog(true, "Bingo", 5);
            //   bingo.Speak();
            Chihuahua hero = new Chihuahua("Hero", true, 7, false);

            hero.Speak();
            GreatDane scooby = new GreatDane(true, "Scooby-Doo", 30, false);

            scooby.Speak();

            List <Dog> dogs = new List <Dog>();

            dogs.Add(hero);
            dogs.Add(scooby);

            dogs.ForEach(d =>
            {
                d.Speak();
                d.Eat("chewToy");
            });
        }
示例#14
0
 public void SubclassesInheritBehaviorFromParentClass()
 {
     var chico = new Chihuahua("Chico");
     Assert.Equal("Chico", chico.Name);
 }