What is a "Contract" when dealing with Interfaces?

I was reading through the asp.net core docs and it said that the interface IActionResult ( public interface IActionResult) Defines a contract that represents the result of an action method.

What does the documentation mean by contract ?

It means that if you implement the interface you agree ( the contract ) to provide concrete methods for all its abstract methods.

1 Like

To expand on what @rickstewart said, on your Interface definition, you just define the methods that your Interface has. But you don’t implement it there.

Then on the class you attach that Interface, that’s where you finally implement the actual code for those Interface methods.

This mean, you can attach your interface on different classes, and all of them will have the same method/action names (thanks to the Interface)… but the actual internal implementation/code may be different for each of these classes.