Versioning in Interfaces
July 4, 2010 Leave a Comment
As interfaces create a contract with the class which implements it, updating or modifying the interface would change the contract as well, thus breaking the version compatibility.
Consider an example:
interface IBase
{
int Add(int num1, int num2);
}
public class Derive1 : IBase
{
#region IBase Members
public int Add(int num1, int num2)
{
throw new NotImplementedException();
}
#endregion
}
Now, if one more method is added in the IBase interface, the class Derive1 would also need to be updated to include an implementation for the newly added method. Thus, breaking the code as Derive1 would not compile without the new implementation.
However, if a new interface is created which inherits the IBase interface and also declares the new method, classes which choose to include the new functionality can implement the new interface and remaining classes can still implement the IBase interface thereby maintaining the version compatibility.