Registering packages in Go without cyclic dependency

The standard library solves this problem in multiple ways: 1) Without a “Central” Registry Example of this is the different hash algorithms. The crypto package just defines the Hash interface (the type and its methods). Concrete implementations are in different packages (actually subfolders but doesn’t need to be) for example crypto/md5 and crypto/sha256. When you … Read more

Cyclic dependency between header files

In the headers, forward declare the member functions: class Node { Tree * tree_; int id_; public: Node(Tree * tree, int id); ~Node(); void hi(); }; In a separate .cpp file that includes all the required headers, define them: #include “Tree.h” #include “Node.h” Node::Node(Tree * tree, int id) : tree_(tree), id_(id) { tree_->incCnt(); } Node::~Node() … Read more

How to deal with cyclic dependencies in Node.js

Try to set properties on module.exports, instead of replacing it completely. E.g., module.exports.instance = new ClassA() in a.js, module.exports.ClassB = ClassB in b.js. When you make circular module dependencies, the requiring module will get a reference to an incomplete module.exports from the required module, which you can add other properties latter on, but when you … Read more