Advantages and disadvantages of interface-Oriented Programming

Source: Internet
Author: User

The following is my understanding of interface-oriented programming.

Advantages:

1.ProgramClear structure and easy to use

2. After the interface is properly designed, it is conducive to program design standardization and can be developed in parallel to improve work efficiency.

3. The program is pluggable, and different implementations are switched for different requirements, reducing the coupling degree. As the complexity of the system increases, this advantage will become more and more obvious.

4. Multiple implementations are allowed to make up for the defects of inheritance.

Disadvantages:

1. the complexity of the design is increased. Poor interface design will affect all interfaces used, and not all programs require interfaces, only when the complexity of the system reaches a certain level can the interface reflect its advantages. Otherwise, it simply increases the workload. Of course, selecting an interface will not be wrong. This must be measured by yourself.

2. may decreaseCodeReusability

3. program execution efficiency may be reduced

Typical Cases of Using Interfaces:

1. JDBC interface. If the standard SQL statements are used, the switching between MySQL and SQL Server only switches to different jar. To support Java, A New DB vendor only needs to implement the JDBC interface of Java.

2. JMS interface. You have selectedApache activemqAs your message-oriented middleware, one day you find Websphere is better suited. After you switch to WebSphere implementation, you will find that you do not need to change much.

If the above design does not use the interface, we will find this situation:

The connection method provided by MySQL. jar is connectmysql (string URL, string username). The connection method provided by sqlserver. jar is connectsqlserver (string username, string URL)

When at least 10 thousand of our programs use the connection method, and all the methods for executing queries, setting parameters, and so on are different, the transformation of the program is undoubtedly very scary.

Interface and inheritance options:

someone asked jams Gosling (father of Java): "What do you want to change if you reconstruct java ?". "I want to discard classes" he replied. After the laughter subsided, it explained that the real problem was not because of the class itself, but the implementation of inheritance (extends relationship ). The implements relationship is better. You should avoid inheritance as much as possible.

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.