| < Day Day Up > |
|
The public member functions declared in a class declaration form the authorized interface to a particular class. Class declarations should be placed in separate header files, thus separating the class interface from its implementation. There are many reasons why you will want to do this and a few of them are discussed below.
Class header files should be named to reflect the class declaration they contain. Take the Foo class as an example. Its declaration appears in a file named foo.h. Its implementation appears in a file named foo.cpp. It is admittedly hard to see the utility in doing this for small numbers of classes but when the complexity of your software project grows, so too grows the number of classes you will have to keep track of and hunt down for additions and modifications. You will see an example of this in the next chapter.
Keeping class declarations in separate header files allows you to create code libraries. These libraries can take the form of a dynamic linked library (DLL) or static library. The benefit to creating code libraries is that you can keep your secret algorithm to yourself while allowing others to benefit from its use. You simply create the library, keep your implementation file to yourself, and distribute the library with the header file. Anyone wishing to use your class library simply includes your header file and links to your library code.
| < Day Day Up > |
|