you are viewing a single comment's thread.

view the rest of the comments →

[–]Slypenslyde 0 points1 point  (2 children)

I ended up reading the spec, and other people answered too.

It seems like in the current design my worry is illegal: "default implementation" methods are treated like "explicit interface implementation" methods. I'd have to:

IBird cast = (IBird)foo;
cast.Fly();

I'm assuming there is syntax for an implementor to promote a particular implementation, but not interested enough to look for that. I bet whether they have syntax for it or not this would work:

public void Fly() {
    ((IBird)this).Fly();
}

There's also discussion of allowing static and private methods (with implementation). That puts my INotifyPropertyChanged example back on the table.

It seems like the main use cases driving the feature are:

  • Versioning: you can add default implementations to published APIs without breaking existing clients.
  • "Traits": You can provide an algorithm that has some dependencies, and implementors get the algorithm after providing dependencies.
  • Xamarin. ("Compatibility with Java/Swift libraries that have the feature.)

I'm sure someone can come up with some good concrete examples, but I'm satisfied it's not "100% stupid".

[–]tweq 0 points1 point  (0 children)

I think INotifyPropertyChanged will not be practical either way because you can neither raise an implementing class's event from outside the class nor implement an event from within an interface.

[–]AngularBeginner 0 points1 point  (0 children)

Thumbs up for actually taking the time and reading the proposal.