Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the significance and advantages of Java interface programming

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about the significance and advantages of Java interface programming. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

What it means in the project:

In the traditional project development process, due to the frequent changes in customer requirements, if we do not use interface-oriented programming, then we must constantly rewrite the existing business code. Rewriting the code may produce a new BUG, and rewriting the code will also affect the classes that call the business, all of which may need to be modified, affecting the stability of the system itself. And in order to minimize the impact of rewriting code, we have to succumb to the current system condition to complete the design, and the code quality and stability are lower. When this situation accumulates to a certain extent, the system will have unpredictable errors, the code is messy and difficult to read, the person who takes over can not understand the code, and the maintenance of the system is getting heavier and heavier, which may eventually lead to the failure of the project.

Interface in the project is a business logic, interface-oriented programming is to extract the customer's business as an interface. The specific implementation of the business is completed through the implementation class of the interface. When the customer needs change, we only need to write a new implementation class of the business logic, and we can complete the requirements by changing the implementation class of the interface in the configuration file (such as Spring framework). There is no need to rewrite the existing code to reduce the impact on the system.

The project based on interface programming has the advantages of clear business logic, easy to understand code, easy to expand and strong maintainability. Even if there is a change of personnel, the newcomers can still get started quickly. For the company, it means more.

Meaning in Java:

Java itself is also a constantly improving language, he is also frequently changing his system API to improve, his API is a huge system, interrelated, if not using interfaces, but using implementation classes, then changes to API will bring instability to the whole system. And if you change the API, there will be a large number of projects using the old API that will not work properly and will lose a lot of customers. In other words, the API that JDK has released is a promise that cannot be changed once released, even if there are various problems with the original API (for example, the java.util.Properties class is a failed example), so there are methods that are not recommended in Java, but JDK still provides this method. And Java language itself is a cross-platform language, in order to meet the requirements of running on various platforms, it is necessary to make various operations into interfaces and write implementation classes under each platform.

The embodiment of design patterns:

The principle of opening and closing in the principle of design pattern is to use interfaces to open to extensions and close to modifications. Among other principles of the design pattern, there is also the principle of interface-based programming, that is, the design principle of relying on inversion (DIP)-the high-level module should not rely on the underlying module. Both should rely on abstraction; abstractions should not depend on details, which should depend on abstractions (Note: from Agile Software Development-principles, patterns, and practices, Robert C.Martin). In the process of using interface-oriented programming, the specific logic is separated from the implementation, which reduces the interdependence between various classes. when each class changes, there is no need to change the written system, just add new implementation classes, and no longer worry about the impact of the newly changed classes on other modules of the system.

Programming is also an art, flexible use of pointers in C language is an art, and flexible use of interfaces in object-facing programs is also an art. Now in the project, the function is becoming more and more complex, and only * classes are designed, which does not make much sense for the whole system. Now the project pays more attention to the integration and maintainability of various functional modules, and the design of the interface becomes more important. Program design is no longer the specific implementation of the design class, but from the whole project to design a highly scalable interface. When you find that you are more and more flexible in using interfaces, you will upgrade from programmer to architect. Unfortunately, I am still a programmer and am working hard like an architect.

In some large projects or large companies, the system interfaces are written by architects, and the specific implementation classes are written by programmers. The bigger the company is, the more obvious this situation is, so we may not know what the written system looks like in these companies. What we do every day may be to "fill in the blanks". It is recommended that you read the book "Agile Software Development-principles, patterns and practices" written by Robert C.Martin, then you will have a new understanding of how to program interfaces.

* hope that everyone can become an excellent system architect.

I remember I once mentioned in a post that an interface can be examined in three ways:

The maker (or coordinator), the implementer (or producer), the caller (or consumer).

In essence, the interface is for the developer to coordinate the relationship between the implementer and the caller.

So the so-called "interface-oriented programming" can be understood as:

The coordination goal of the developer can be achieved only if both the implementer and the caller follow the principle of interface-oriented programming.

A clich é example is JDBC.

Advantages:

The interface and implementation are separated and are suitable for team collaborative development.

More specific advantages: you can refer to the IDP principle.

Disadvantages:

The design is difficult, when you do not write the implementation, you have to think of the interface, the interface changes, all messy, this is the so-called design is more difficult than implementation.

So the people who design the interface have high wages!

Thank you for reading! This is the end of the article on "what are the significance and advantages of Java interface programming". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report