Many people know the implementation of interfaces, but the implementation method of interfaces is dividedDisplay implementationAndImplicit implementationI don't know if many people know it! However, I think the company's technical department seldom mentioned this. I just want to write this blogs. Common Methods:
Public interface IReview
{
Void GetReviews ();
}
Public class ShopReview: IReview
{
Public void GetReviews (){}
}
This method isImplicit implementation:
IReview rv = new ShopReview ();
Rv. GetReviews ();
ShopReview rv = new ShopReview ();
Rv. GetReviews ();
You can call the GetReviews method.
Another way isDisplay implementation
Public interface IReview
{
Void GetReviews ();
}
Public class ShopReview: IReview
{
Void IReview. GetReviews (){}
}
This interface is implemented.
GetReviews can only be called through interfaces:
IReview rv = new ShopReview ();
Rv. GetReviews ();
The following method willCompilation Error:
ShopReview rv = new ShopReview ();
Rv. GetReviews ();
Conclusion:Both the implicit implementation interface and class can access the display implementation. Only the interface can be accessed.
Show implementation benefits
1. Implementation of hidden code
2: In the system accessed through interfaces, callers can only access the system through interfaces instead of the underlying classes. PS: it can be applied to the company's current interface + Sevice architecture system. To avoid this, we always require you to access the service through interfaces. This is because interface access is not required now.