c++ - Mutual update between two classes of same superclass -


i have opengl application 2 main parts (viewers), main loop follows:

int main(int argc, char* argv[]) {     gp::viewers::patternviewer pviewer;     gp::viewers::meshviewer mviewer;      while (!pviewer.shouldclose() && !mviewer.shouldclose())     {         pviewer.makecurrent();         pviewer.mainloop();         pviewer.swap();          mviewer.makecurrent();         mviewer.mainloop();         mviewer.swap();          glfwwaitevents();     }      glfwterminate();      return 0;  } 

it happens user interaction 1 viewer should propagate change other viewer. gut instinct says update loop follows:

int main(int argc, char* argv[]) {     gp::viewers::patternviewer pviewer;     gp::viewers::meshviewer mviewer;      while (!pviewer.shouldclose() && !mviewer.shouldclose())     {         pviewer.makecurrent();         pviewer.mainloop();         pviewer.swap();          mviewer.makecurrent();         mviewer.mainloop();         mviewer.swap();          // update here         mviewer.update(pviewer);         pviewer.update(mviewer);          glfwwaitevents();     }      glfwterminate();      return 0;  } 

but in case, patternviewer needs know meshviewer, , meshviewer needs know patternviewer - circular dependency. moreover, isn't clear if mviewer.update(pviewer) should update pviewer whatever updates available mviewer, or vice versa. seems me should former - mviewer should know updates propagate, not pviewer.

it should mentioned patternviewer , meshviewer both inherit abstract superclass viewer.

is there way of resolving circular dependency? there accepted way/design pattern handling case?

isn't information shared between viewers visible in viewer, is, in base class? if so, abstract viewer needs know how update abstract viewer there's no need each concrete viewer such patternviewer or meshviewer know concrete viewer — in other word, there's no need circular dependency.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -