Header file contains the Interface and Library contains the implementation
It's the fundamental difference between "interface" and "implementation"; the interface (header) tells you how to call some functionality (without knowing how it works), while the implementation (library) is the actual functionality.
Note: The concept is so fundamental, because it allows you flexibility:
you can have the same header for different libraries (i.e. the
functionality is exactly called in the same way), and each library may
implement the functionality in a different way. By keeping the same
interface, you can replace the libraries without changing your code.
And: you can change the implementation of the library without breaking
the calling code!
When you are optimising a program, you would most likely modify the source file to improve the algorithm, but the header file wouldn't change, because external clients still call the methods using the same set of parameters and return values.
While there is nothing stopping code from being implemented in a header file, this is generally not favoured as it can introduce extra coupling and dependencies in the code.
When you are optimising a program, you would most likely modify the source file to improve the algorithm, but the header file wouldn't change, because external clients still call the methods using the same set of parameters and return values.
While there is nothing stopping code from being implemented in a header file, this is generally not favoured as it can introduce extra coupling and dependencies in the code.
No comments:
Post a Comment