Can you give me an almost overly simplistic understanding of abstract class vs inheritance use and help me so I can truly understand the concept and how to implement? I have a project I'm trying to complete, and am lost on how to implement. I've been chatting with my professor and been told off pretty much, saying that if I can't figure it out, I'm probably not ready for the course. I have OVERCOVERED the prerequestite courses, and still have trouble understanding these concepts.
To clarify, the project as I've done so far is below. I don't have the dog/cat classes etc filled out yet. Can you give me a pointer. I'm not asking for anyone to give me the "answers." I just am lost on where to go with this. I take online courses and his communication efforts with me have been troubling. I just finished with 4.0 with all my other courses, so I'm willing to put the effort in, but I'm lost in the comprehension of these concepts and how to PRACTICALLY apply them.
Any comments or help that will let me progress further in this project?
The description of what I'm to implement is as follows:
Overview:
The purpose of this exercise is to demonstrate the use of Interfaces, Inheritance, Abstract classes, and Polymorphism. Your task is to take the supplied program shell and ADD the appropriate classes and corresponding class members/methods to get this program to function correctly. You may not make changes to any of the code supplied, you may only add the classes you write. Although there are numerous ways to get the program working, you must use techniques that demonstrate the use of Interfaces,
Inheritance, Abstract classes, and Polymorphism. Again, to make clear, you can add to the supplied code but you cannot change or delete any of it. The code that is supplied will work with very little additional code and will satisfy the requirements of the exercise.If you successfully complete the assignment, your program should output the following statements when run:
My name is Spot, I am a Dog
My name is Felix, I am a Cat
Requirements:
1) You must have an abstract base class called 'Animal' from which the Dog and Cat classes derive.
2) The Animal base class must derive from the Interface 'IAnimal', it is the only class that should derive from IAnimal.
3) Since all animals have a name and a name is not an attribute that is specific to a dog or a cat, the Animal
base class should be where the name is stored and where the WhatIsMyName get-property is implemented.
4) You will need to create a Dog and a Cat class that will derive only from the Animal base class.
5) The Dog and Cat classes should implement the WhatAmI get-property and return the appropriate string value.
Code you can't change:
using System;
namespace IT274_U2
{
public interface IAnimal
{
string WhatAmI { get; }
string WhatIsMyName { get; }
}
public class TesterClass
{
public static void DescribeAnimal(IAnimal animal)
{
Console.WriteLine("My name is {0}, I am a {1}", animal.WhatIsMyName, animal.WhatAmI);
}
static void Main(string[] args)
{
Dog mydog = new Dog("Spot");
Cat mycat = new Cat("Felix");
DescribeAnimal(mydog);
DescribeAnimal(mycat);
}
}
}
///////////////////////
Code I've written so far:
using System;
namespace IT274_U2
{
public interface IAnimal
{
string WhatAmI { get; }
string WhatIsMyName { get; }
}
public class Dog
{
public abstract string WhatAmI
{
get;
set;
}
}//end public class Dog
public class Cat
{
public abstract string WhatIsMyName
{
get;
set;
}
}//end public class Cat
public abstract class Animal : IAnimal
{
// fields
protected string Dog;
protected string Cat;
// implement WhatIsMyName
//properties
public abstract String Dog
{
get;
set;
}
public abstract String Cat
{
get;
set;
}
public abstract string WhatIsMyName();
} //end public abstract class Animal
public class TesterClass
{
public static void DescribeAnimal(IAnimal animal)
{
Console.WriteLine("My name is {0}, I am a {1}", animal.WhatIsMyName, animal.WhatAmI);
}
static void Main(string[] args)
{
Dog mydog = new Dog("Spot");
Cat mycat = new Cat("Felix");
DescribeAnimal(mydog);
DescribeAnimal(mycat);
}
}
}