Thinking of constants in Java interface

Source: Internet
Author: User

The implementation of the method is not allowed in the interface, and the abstract class is allowed to implement the method and define the variable, so we can see that the interface is a higher level of abstraction than the abstract class. If an interface can define a variable, but the method in the interface is abstract, the property cannot be modified in the interface through the behavior (for example, the set () method). Then some people will suggest that you can modify the properties of an interface by implementing an instance of the class that implements the interface. Well, if there is a variable C in the interface, we change the value of C by implementing its Class A object, then Class B of the interface, C variables in Class C will be changed, imagine this will cause confusion, many want to implement the interface of the class do not know the interface is now what the C variable value, because the interface is changing, It is no longer a high-level abstraction, but a mutable ingredient. The so-called abstraction is to put some immutable things together, and mutable things are often placed in the implementation.

So we think about the meaning of the interface, in fact, it is a class of things properties and behavior of high-level abstraction, it embodies the OCP (to modify the closure, open to expansion) principle, which is our software development has been pursued.

Thinking of constants in Java interface

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.