Sometimes, a header file uses objects that are in declared in other header files. The user of this header file would have to include the dependency anyway and get the order correct too.
Assuming we are talking about C/C++ like languages that use
It is best (like all rules of thumb there are exceptions) to include only the things you explicitly need.
Anything that is not explicitly needed should be forward declared. This helps to prevent cycle dependencies in the code. Also when you do maintenance on the code it prevent you accidentally removing dependencies that have been implicitly introduced.
Full class definitions are needed if:
- You inherit from them
- You have member objects of that type (not pointers or references).
- You have parameters passed by value of that type.
If you just use something by reference then you should try and use a forward declaration.