Years ago i had a course about OO where a statement was made.
I forgot that statement and would like some help getting it back to memory.
It was one of the following:
- Everything you can do with an interface can also be done with a delegate
- Everything you can do with an interface can also be done with inheritance
- Everything you can do with inheritance can also be done with a interface
- Everything you can do with an inheritance can also be done with a delegate
I know its one of them and that 1 is bound to be totally invalid
Can you please shed some light on this?
I agree with IAbstract – delegates have nothing to do with inheritance or interfaces so I don’t think any of the statements apply.
In my opinion #2 is the correct answer. An interface provides a set of methods, properties, and events that a implementing class must contain. You get this by default with inheritance: all of the superclass’s non-private properties, methods, and events are available to the subclass.
Inheritance provides implementation details (a method body) to a subclass, whereas an interface does not; it only provides what will be available in a given class. This is why I don’t think #3 is correct.