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:
The hidden implementation interfaces and classes can be accessed.
Only interfaces can access the display implementation.
Show implementation benefits
1: HideCodeImplementation
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.
-- =Happy reading= --
Google Tag: interface, implicit display implementation, display implementation