Separating A Class s Interface From Its Implementation

 < Day Day Up > 



Separating A Class’s Interface From Its Implementation

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.

Manage Physical Complexity

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.

Allow the Creation of Code Libraries

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 > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net