On the Service Layer Interface why have

Original Address: https://www.cnblogs.com/chyu/p/6147907.html

People are free to say one thing, why each service layer must write an interface to it, although much trouble - to say something, but do not know where to start, I had to re-organize his thoughts.

Scenario 1 : There is a lot of open source frameworks such cases, a feature that allows users to custom extensions put it plainly, it provides an interface, we only need to implement this interface to achieve on our own logical complement, you can. let us follow the framework of logic to perform. the question is, does not know what the framework of our implementation class is, if you do not define an interface, then how can we call in the framework of the implementation class it?

Scenario 2 : My colleagues and I are doing the project two different functional modules, but the function of colleagues they need to call a logical part of my head to make him realize there is a "placeholder" is available, I should not fast. write interfaces threw him?

Scenario 3 : an adapter function, or that a simple factory class, if not defined interface, then the face of numerous implementation class, how does it work uniform?

Scenario 4 : Want project code in line with some kind of "standard", but it is impossible to look at someone else write the code it, it easy to handle, first-out set of interfaces, and then you will figure ~

Scenario 5 : the Java there is no multiple inheritance, but can implement interfaces and more, then there is a very interesting thing, such a class can implement multiple interfaces, and this time the interface part of the method implementation class can be exposed have a choice, do to "narrowing" to achieve the purpose of the class functionality.

.. Of course, there are many examples of these cases can actually be said to reflect the benefits of the interface, it has been suggested java program to interfaces, but said back layer must have Service Interface? That may not be to, because after all, just one more Interface there are certain circumstances under the scalability and advantage, but whether the case will use the convenience of the interface, we may not have to uncertain is "likely" to pay. just write a few lines of code, it is possible to pay a little to avoid " future "big" trouble ", why not!?

Guess you like

Origin www.cnblogs.com/asplover/p/12450899.html