Reputation: 38180
From this blog:
I’ve been programming in Java for over 16 years and teaching it for nearly half that time. So it’s going to take a little practice to stop repeating this sentence: “Interfaces may only contain methods that are public and abstract.” As of Java 8, that statement is no longer true. It is now possible to add both instance and static methods to Java interfaces.
Does new C# version allow this also or will in some intended future?
I always felt Interface was good in theory but in practice caused many kind of maintenance nightmare on your interface consumers as described in the article.
Update : I'm also interested by the critics, all the more if you have read the author's article especially about abstract class alternative as not solving real world problem.
Upvotes: 2
Views: 112
Reputation: 156948
It is to the implementing class in C# to determine the scope of the method or property implemented. C# knows implicit and explicit interface implementation, which helps to set the scope of the method. (You can create a secondary method or property that has the wanted scope (internal
, private
, protected
).
Static interface methods are not possible in C# and I wonder why you would want that. Static methods are bound to the type and not to the instance, so you can't call this.StaticMethod
for example. That makes defining them on interfaces useless.
And default methods are just... horrible. Make an abstract
class. Period.
Upvotes: 1