CppCon 2016: John Lakos “Advanced Levelization Techniques (part 1 of 3)"
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about circular includes, forward declarations and header include order, since Lakos explains the underlying physical design principles.
Recommended by 2 people across 2 different months, 2017 to 2024.
What it is
A CppCon 2016 talk by John Lakos of Bloomberg, author of "Large Scale C++ Software Design", on physical design for large C++ codebases. It reviews the basics, then presents levelization and insulation techniques with real-world examples to avoid cyclic or excessive dependencies. This is part 1 of 3.
What people said
Recommends Alex · 2017-03 · Stack Overflow · on “Circular Inclusion using Singleton and child class”
The first of all, please don't write implementations of functions in headers unless it is not inline or template. Try the following: base.h #include <memory> class Player; class Level; class Base { public: static Base& instance(); private: Base(); unique_ptr<Player> player; unique_ptr<Level> level; } base.cpp #include "base.h" #include "player.h" #include "level.h" Base::Base() : Player(make_unique<Player>()), Level(make_unique<Level>()) { } static Base& Base::instance() { static Base base; return base; } And you should watch the following : [this video]
Recommends Justin · 2017-12 · Stack Overflow · on “What are the risks to massively forward declaration classes in header files?”
IIRC, this talk by John Lakos [this video] (it's 3 parts; not short) mentions a good pattern on when to forward declare, or at least a good pattern for Bloomberg.
Cites Dr. Gut · 2024-02 · Stack Overflow · on “Including the corresponding header first. What problems does it NOT solve?”
There is a similar rule in most style guides: Include the .hpp in the corresponding .cpp as the first substantive line of code. Even if the .cpp is otherwise empty. The latter sentence is popularized by John Lakos. See e.g. CppCon 2016: John Lakos “Advanced Levelization Techniques (part 1 of 3)", at 7:28: [this video] This rule ensures, that our headers are self-contained, i.e. they compile in isolation, or in other words they don't require other headers in front of them to compile. But, does this ensure, that we will never have include order dependencies?