Interview Questions

From a versioning perspective, what are the drawbacks of extending an interface as opposed to extending a class?

C# Interview Questions and Answers


(Continued from previous question...)

82. From a versioning perspective, what are the drawbacks of extending an interface as opposed to extending a class?

With regard to versioning, interfaces are less flexible than classes. With a class, you can ship version 1 and then, in version 2, decide to add another method. As long as the method is not abstract (i.e., as long as you provide a default implementation of the method), any existing derived classes continue to function with no changes. Because interfaces do not support implementation inheritance, this same pattern does not hold for interfaces. Adding a method to an interface is like adding an abstract method to a base class--any class that implements the interface will break, because the class doesn't implement the new interface method.

(Continued on next question...)

Other Interview Questions