Requirements:
1) security technical security needs. Even if the core implementation is not visible in the library, some internal information is still exposed in the variable definition in the header file;
2) the need to save Compilation Time. At the initial stage of development and design, the implementation needs to be changed frequently, and variable definitions in the header files need to be changed frequently. Therefore, the header files need to be compiled during re-compilation, which sometimes leads to a long Compilation Time.
Solution:
The handle class can solve the above problems:
// : Handle. h -- handle classes
# Ifndef handle_h _
# Define Handle_h _
Class Handle {
StructCheshire;//Class declaration only
Cheshire*Smile;
Public:
Handle ();
Void doit ();
~ Handle ();
} ;
# Endif // Handle_h _
This is for all customersProgramAs you can see, struct Cheshire is a type description or class description that is not completely specified and will be used to store real variables. It tells the compiler that Cheshire is the name of a structure, but does not provide anything about the structure. This is sufficient for generating a pointer to the structure.
In this technique, the structure entity that contains the specific implementation is hidden in the implementation file.
// : Handle. cpp -- handle implementation
# Include " Handle. h "
// Define handle's implementation
Struct Handle: Cheshire {
IntI;
} ;
Handle: handle () {
Smile=(Cheshire*) Malloc (Sizeof(Cheshire ));
Smile->I=0;
}
Void Handle: doit () {
//Do something with I
}
Handle :: ~ Handle () {
Free (SMILE );
}
The use of the handle class is the same as that of any class, including header files, object creation, and sending information. However, with this design, the variable design is hidden, and the header file does not need to be re-compiled during changes. Bruce said that although this is not perfect information concealment, it is a great improvement after all.