Java learning: white box reuse and black box reuse
1. white box reuse: This is also called inheritance reuse. Child classes inherit all the things of the parent class,
To some extent, white box reuse destroys encapsulation. Is a relation of is.
Example: class Liucy {
Public voidteachCpp () {System. out. println ("Teach Cpp ");}
Public void chimogu (){}
}
Class Huxy extends Liucy {}
2. Black Box multiplexing: it is also called combination multiplexing, which is a kind of has a relationship.
Example: class Liucy {
Public voidteachCpp () {System. out. println ("Teach Cpp ");}
Public void chimogu (){}
}
Class Huxy {
Private Liucy liucy = new Liucy ();
Public void teachCpp () {liucy. teachCpp ();}
}
Principle: Combination reuse replaces inheritance reuse.
This gives us the opportunity to select this reusable feature.
The best java training institution in Shanghai ziqin, free of charge! Employment and base salary protection to solve all students' concerns: http://www.shziqin.net/gqindex.aspx