Possible Duplicates:
Interface vs Base class
When should I choose inheritance over an interface when designing C# class libraries?
So I’m writing my first real program in C#. The program will scrape data from four different websites. My plan is to have one parent class that will look like this:
class Scraper
{
string scrapeDate(url);
string scrapeTime(url);
//&c.
}
Then I will have four classes that inherit from it.
The other option is to make Scraper an interface and have four classes implementing it.
What are the differences between these approaches?
Class inheritance represents an “is-a” relationship, e.g., a
Tankis aVehicle. If your situation doesn’t at least meet this, choose interface over inheritance.If the proposed base class doesn’t provide default implementations for your methods, this would be another reason to choose interface over inheritance.
In C#, you can only inherit from one class but multiple interfaces. This would be yet another reason to choose interface over inheritance.
Get the idea?