I was reading about code architecture and the MVC/MVVP paradigm. Ideally, we should have the model as a high-level policy/component where it should not know or directly depend on other components, such as the view. Essentially, one of the roles of the controller is to send inputs to the model and thus has the model component as a dependency. However, we need the model needs to communicate with controller whenever it's state changes. From my understanding, we shouldn't have the model depend on the controller as it would we would create a bidirectional dependency between the components, which can lead to unmaintainable code and difficulty adding changes. So, I imagine the bidirectional relationship to communicate as the following:
However, if we create an interface for the model to communicate with the controller,
IController, it can remove this bidirectional communication.
IController implements all the methods that notify the controller changes. The dependency would look like the following:
Now, the model is ignorant of the actual implementations of the controller. Therefore, changes in the controller, should not affect the model components. I was wondering if adding an interface for the controller the best way for model and controller to communicate with each other.
I am also aware that in some programs, the model can directly communicate with the view directly using the observer design pattern. However, the model should not know the implementation details of the view since the model should be respected with high-level policy and should not know about low-level policies, such as the view. Therefore, in this case, let's not consider the observer pattern for the model to communicate the view.