Well,
you've pretty much answered it already
it's primarily for modularised code, and code reuse
Splitting files into Declaration (Header) and Implementation (source) files is a common concept, used in both procedural and OOP
however, it comes into it's own with OOP, so I'll stick with that
One of the core OOP concepts is the ability to hide the internal "workings" of an object, and only show certain, outward facing functions
you have your main program,
and it uses some object
You don't need to know "how" that object actually works internally
You only need to know how to use it
Classic example is the standard string library
you know how to use the string library
but you don't need to know exactly how it works
(all the dynamic allocation and resizing of buffers, and whatnot, is completely hidden)
You just #include the declaration and off you go
Code re-use also becomes important here, as well
if you have a common object that is used in many of your files, why keep repeating the same code?
Bung the object in a linked library and #include the objects header file in your source files (so they know how to use the library)
All of your files, when calling the common object, re-use the same library
|
|
Bookmarks