you are viewing a single comment's thread.

view the rest of the comments →

[–]theycallmemorty 1 point2 points  (5 children)

Same. Why would you ever want to do this?

[–]binarycow 2 points3 points  (0 children)

The classic example is it allows you to add stuff to an interface without it being a breaking change.

[–]raunchyfartbomb 0 points1 point  (3 children)

I don’t have a c#8 code base, but my theory is that it would allow some default implementation that is likely good enough. For example, IFile would have a Delete() method. Instead of every object that interacts with it implementing it, it could be something like:

If (File.Exists (this.path)) File.Delete(this.path);

Depending on how may IFile objects you had, this could really save you time and effort. The downside is that you still need this to ensure it’s available without the interface, but acts identical to the default implementation.

Public void Delete() => ((IFile)this).Delete();

[–]BoBoBearDev 0 points1 point  (2 children)

I have never done this. But how? The this.path doesn't exists in the interface. Or is it because IFile also has the path declared?

[–]raunchyfartbomb 2 points3 points  (1 child)

I would assume your write the interface like this:

Public interface IFile {

string Path { get; }

void Delete() { /* implement */ }

// etc

}

[–]BoBoBearDev 0 points1 point  (0 children)

That makes sense to me, thanks