The $1,000,000 Interview Question
"What is the difference between an interface and an abstract class?"
"Errrrrrrrrm.... well one's a class, and the other is, ummmmmmmmmm...."
This is a common question that can make or break an interview. Throughout the Journeyman Regimen, I've come to appreciate the importance of this question. Answering it incorrectly can be a huge red flag to the interviewer. Perhaps if everyone reads this post, the interface/abstract class question will no longer be the stumbling block of entry to junior level programmers. I'll also shed some light on why this question comes up again and again.
In short, the textbook answer is that an abstract class is inherited, while an interface is implemented. C# and related languages can only inherit from a single class but can implement multiple interfaces. An abstract class can implement members and methods, while an interface cannot. All method and member signatures of an interface must be implemented. Classes inherited from an abstract class need not implement every member and method of the abstract class.
So what's the big deal?
In the 20th century, Object Oriented Programming became all-the-rage. Inheritance was slathered all over code to create complicated taxonomies and dependencies that ape real-life concepts. Inheritance is easy-to-grok for programmers because it can be mapped to real-life relationships and can be applied almost everywhere. For a bit it was the one-solution-to-rule-them-all.
Like most things, inheritance is not a magic pill. There is no magic pill. If you've ever fooled around with OOP coding, you've probably experienced an explosion of classes that create a complex shit show that is hard to understand and can never be reused. While it's still a critical concept, early OOP folks overused inheritance.
That's where object composition comes in to save the day. Replacing pure inheritance with programming to interfaces using different structures, while introducing new abstraction, encourages reusability, fewer dependencies, and more maintainable code.
That doesn't mean that inheritance doesn't have a place. It is often simpler to inherit from a class rather than introduce layers of abstraction. It all depends on the situation.
Well that's it for now. I guarantee that in almost every interview you will encounter this question. It doesn't hurt to be ready.