What is the benefit of Java defining interface variables for receive types (interface-oriented programming)

Source: Internet
Author: User

Personal understanding: The definition of interface variables for the receiving type is interface-oriented programming, through the abstraction of the interface can reduce the coupling between classes, increase reusability.

Interface-Oriented Programming:

A normative constraint

    • The creator (or coordinator), the creator (or producer), the caller (or the consumer).
    • An interface is essentially a set-up that coordinates the relationship between the creator and the caller.
    • Only the implementation and the caller follow the "interface-oriented programming" principle, the coordination purpose of the creator can be achieved.
    • The semantics of an interface are can-do semantics, table constraints (Constraint).
    • Like the Spec API for JDBC, no matter which implementation you use, we use the same API.

Separation design and implementation

    • Enables the system to support the open and closed principle and the dependency reversal principle. The designer can design the interface, and the programmer can write the implementation according to the interface.

Decoupling

    • To some extent, the dependency interface is not dependent on the implementation, and the effect can be minimized when the implementation class is replaced.

Easy to do unit testing

    • In the case of dependent interfaces, unit testing is easier, and using mocks is easier, in TDD, the test driver is to make the program easy to test.

Related to design

    • In an object-oriented system, the various functions of the system are accomplished by many different objects.
    • In this case, it is less important for the system designer to implement their own internal objects.
    • The collaboration between the objects becomes the key of the system design.
    • In the OSGi specification, the separation of interfaces from implementations is most thoroughly used.

The IOC of Spring

    • Spring hides the process of creating a class, which is actually a large factory that makes our code more concise and easier to manage and test.

Reference:

http://ask.csdn.net/questions/217447

http://blog.csdn.net/u010382560/article/details/48051355

Http://www.cnblogs.com/chaohi/archive/2008/10/23/2330442.html

http://blog.csdn.net/u013400743/article/details/51252003

Http://www.cnblogs.com/xyqCreator/archive/2012/11/06/2756687.html

http://blog.csdn.net/greenlihui/article/details/61916129

Https://www.cnblogs.com/feng9exe/p/5588671.html

http://blog.csdn.net/jj_nan/article/details/70161086

http://blog.jobbole.com/44559/

http://blog.csdn.net/fireofjava/article/details/17527463

What is the benefit of Java defining interface variables for receive types (interface-oriented programming)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.