1

I'm developing a level editor in Java. I'm designing its code in MVC. From what I've learned: controllers can have a direct reference (fields) to views and models. Views can have direct reference to models but shouldn't have to controllers (they can interact controllers via design patterns such as observers) and models shouldn't have any direct references to any views or controllers (also should use observer). My question is: How should controllers interact each other? Two-way references is not recommended AFAIK, so how should they interact each other? This question can also be relevant between viewers. Thanks

Greg Burghardt
  • 34,276
  • 8
  • 63
  • 114
Gad Wissberg
  • 119
  • 4
  • 2
    related (possibly a duplicate): [Is a good practice to call a Controller function from another Controller?](https://softwareengineering.stackexchange.com/a/264402/31260) – gnat Aug 01 '18 at 07:31
  • Controllers should generally focus on all the logic it requires, and, if necessary, reuses utility classes or derives from a base class for any and all shared logic. Direct communication between controllers is generally discouraged, though if you must, you should probably consider using events rather than direct calls. – Neil Aug 01 '18 at 07:35
  • "controllers can have a direct reference (fields) to viewers" - really? Isn't the controller supposed to not know anything about the view? – Frank Puffer Aug 01 '18 at 08:18
  • @FrankPuffer afaik yes, it can have a direct access. Like this example from wikipedia: https://upload.wikimedia.org/wikipedia/commons/b/b5/ModelViewControllerDiagram2.svg – Gad Wissberg Aug 01 '18 at 08:25
  • 1
    how about https://softwareengineering.stackexchange.com/questions/316931/is-there-a-good-formal-pattern-to-manage-state-in-mvvm/316958#316958 – Ewan Aug 01 '18 at 10:24

0 Answers0