When looking at a UML diagram Nioeventloop in Netty, it feels very complex, as shown in:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/08/7D/wKiom1njEjSTKK1FAAD_bnD1apY230.png "style=" float : none; "title=" 001--original. png "alt=" Wkiom1njejstkk1faad_bnd1apy230.png "/>
Can not find the focus, can't find the main line, at this time the heart is born without love.
Thus, a question that has plagued me for a long time has been aroused: what is the relationship between inheritance and interface?
This question, also consulted colleague a few days ago, also did not say what key point.
Then, after a long meditation on the figure, I finally realized a bit of my own opinion: "The following is for reference only"
1, inheritance, is a blood relationship, is a family, is living (feel life characteristics);
A class can have only one parent class, you can call/inherit the parent class's API directly, or overwrite the parent class's API
2 , interface, is a tool, is an embodiment of the auxiliary function; it is dead (inanimate nature, just a tool);
As a class implements the interface, it is like a person, wearing Iron Man's clothes, the ability to greatly increase, but its essence is a person;
Or, a person, with a car, after the plane, the speed of this person greatly improved; but, in essence, a person;
These Iron Man clothes, cars, airplanes, mobile phones is a tool, a specific component, module, or plug-in, is
The function of an additional helper class, or the function of an auxiliary person, does not change the fundamental attributes of a person.
Therefore, the class is also, the same class can implement different interfaces at the same time (if you can have a car, or wear Iron Man's clothes) but,
Does not change in nature, only increases/increases the additional capacity
Inheritance, is a kind of blood relationship performance;
interface, which is the extra tool for the class.
At this point, re-modify the diagram above, remove the interface (that is, remove the extra functionality, see the Essence), as follows:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/08/7D/wKiom1njEjTxV_AdAADqEbsc08s046.png "style=" float : none; "title=" 002--remove dashed lines. png "alt=" Wkiom1njejtxv_adaadqebsc08s046.png "/>
It can be seen that there should be 3 main lines, and then the specific analysis.
When we learn the same thing, it is best to have their own ideas, opinions;
Simply relying on others ' summaries may not be well understood;
It may be best to speak in your own language.
This process may need to go through a lot of data to summarize and organize,
Once successful, it can be remembered for a long time.
Can you explain to others, to verify that you really have no real control.
This article is from the "Xej Distributed Studio" blog, so be sure to keep this source http://xingej.blog.51cto.com/7912529/1972496
The relationship between Java inheritance and interfaces