EP 4 : Default Interface Methods in C# 8.0
We have been using the interfaces for years and we know that interfaces are just contracts and the class that inherits them must implement all methods of interface.
Suppose this Interface is being implemented by multiple classes and now you want to add some more methods in that interface.
If we talk about the time before C# 8.0 then you can not do this, because it will break all classes implementing that interface and you must implement that method.
But with C# 8.0 now we can add the default implementation of methods and it will not break all those classes that are implementing the interface.
So what are the benefits of using it
Without breaking the default implementation we can add new methods now in the interface, but we can do this through an extension method as well ( creating an extension method for your interface).
The class implementing the interface is not aware of the default implementation of the method.
Most importantly default interface methods can avoid the diamond problem
There are 3 ways you can help me in growing:
Subscribe to my YouTube Channel
Subscribe to my Weekly .NET Newsletter of C#/.NET
Download my eBook at Gum Road which contains 30+ .NET Tips