C# 8 Interface Default Implementation

308 Views Asked by At

Dear editors, Why you mark this question as Opinion-based? I have no opinion, I just asked a basic question.

I have a basic confusion with C# 8 Interface implementation concept, As you know Interface is not more than a Contract, Why we need to default implementation? Is it correct conceptually? Why a Contract must have an Implementation?

1

There are 1 best solutions below

1
On

Suppose we inherited from an interface in different places if we wanted to add a new member and we don’t want to affect any existing class with this change. This is how we define interface with current version of C# and we are stuck. In C# 8.0 we can solve the problem by providing implementation to method.

Default implementations is powerful language feature coming to C# 8.0. Although it may seem dangerous for some developers then others will certainly be happy with it. Those who are writing libraries and components for public use may find default implementations specially useful as they let us avoid breaking changes in interfaces.

Document