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.
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
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:
If you just use something by reference then you should try and use a forward declaration.