Function of Java programming interface call and code sharing

Many junior Java programmers are confused about the meaning of the interface. I don't know what the interface does and why it is defined.

It seems that defining interfaces is redundant work in advance. Here I summarize four points about the significance of interfaces in Java:

1. Importance: in the Java language, abstract class and interface are two mechanisms that support the definition of abstract classes. It is precisely because of the existence of these two mechanisms that Java is endowed with powerful object-oriented capabilities.

2. Simplicity and standardization: if a project is relatively large, an architect who can sort out all businesses needs to define some main interfaces. These interfaces not only tell developers what businesses you need to implement, but also limit the naming specification (prevent some developers from naming casually, which makes other programmers unable to understand).

3. Maintenance and expansibility: for example, you need to make a Sketchpad program, in which there is a panel class, which is mainly responsible for painting functions, and then you define this class.

But in the near future, you suddenly find that this class can't satisfy you, and then you have to redesign this class. What's worse, you may have to give up this class, so other places may reference it, which is very troublesome to modify.

If you define an interface at the beginning, put the drawing function in the interface, and then implement the interface when defining a class, then you just use this interface to refer to the class that implements it. If you want to change later, you just refer to another class, so as to achieve the convenience of maintenance and expansion.

4. Security and tightness: interface is an important means to realize software loose coupling. It describes all external services of the system without involving any specific implementation details. In this way, it is safer and tighter (generally, software service providers consider more).

Method of Java calling interface

summary

The above is all about the sharing of Java programming interface calling code in this paper. I hope it will be helpful to you. Interested friends can continue to refer to this site: Java programming realizes the addition, deletion and modification of data through the list interface, check code examples, talk about Java interface oriented programming, talk about Java interface oriented programming, etc. if you have any questions, you can leave a message at any time, and the editor will reply to you in time. Thank you for your support!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>