9.4. Separating Interface from ImplementationIn Chapter 3, we began by including a class's definition and member-function definitions in one file. We then demonstrated separating this code into two filesa header file for the class definition (i.e., the class's interface) and a source code file for the class's memberfunction definitions (i.e., the class's implementation). Recall that this makes it easier to modify programsas far as clients of a class are concerned, changes in the class's implementation do not affect the client as long as the class's interface originally provided to the client remains unchanged. Software Engineering Observation 9.6 Actually, things are not quite this rosy. Header files do contain some portions of the implementation and hints about others. Inline member functions, for example, need to be in a header file, so that when the compiler compiles a client, the client can include the inline function definition in place. A class's private members are listed in the class definition in the header file, so these members are visible to clients even though the clients may not access the private members. In Chapter 10, we show how to use a "proxy class" to hide even the private data of a class from clients of the class. Software Engineering Observation 9.7
|