Java foundation - Interface

  • Basics: declare an interface keyword interface, implement the interface keyword implements. A class can implement multiple interfaces.
  • Interface in content:
    the relevant member variables default modifier 1. (must) be public static final (because it is final it must show initialization assignment)
    2. The default method (must) be public abstract of
    3.jdk8 later added two methods : default and static. Achieve class can "inherit" default direct use, the interface name .static methods.

We generally to a system interface as the channel to the external display functions, and abstract classes can be used to customize the extension point system.

When a system is to use a class inheritance tree, generally it will be variable declaration for the upper abstract type (parent) that is upcast inheritance tree, the use of multi-state (a system want to eat the cat out of the way, but animal systems Interface to provide an animal eating an excuse, a system: animal haha ​​= new cat (); haha ​​eat (); on it), to achieve a loose coupling of the two systems. (If I need to eat my dog ​​New dog on it directly, without changes to the source code).

Reproduced in: https: //www.jianshu.com/p/fa0953d72e17

Guess you like

Origin blog.csdn.net/weixin_34007291/article/details/91330378