object - c++ dependency injection and more complex structures -


i'm trying understand di , separation of object construction , logic, have problems implementation in cases. here example.

class { public:     void load_bs(); // create bs , push them bs_ vector                     // , call load_cs on every created b private:     std::vector<b> bs_; };  class b // not need reference real work { public:     void load_cs(); // create cs , push them cs_ vector private:     std::vector<c> cs_; };  class c // needs , b { public:     c(a &a, b &b) : a_(a), b_(b) {}  private:     &a_;     b &b_; }; 

how can construct structure according di? first create instance of class, call load_bs() method , create b objects, it's time create c objects in b instance. since should inject object dependencies needed object, not pass through use in object, reference inside b during c creation? mean c should created somewhere else , passed b?

when inject dependency injected else real hard refactoring when 1 of these dependencies should removed or when want add new 1 available in object somewhere real high in hierarchy.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -