Versioning in Interfaces

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. :)

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.