0

According to my understanding, in the MVC design the Model can only receive the functions calls from the Controller and not from the View directly.

Is it true that the Model can change or access the View directly?

3
  • 1
    How would that look? Do you have code samples?
    – bobek
    Commented Mar 3, 2020 at 16:12
  • I dared to slightly edit the text to put the question at the end. I also highlighted the MVC components, since you refer to them in a very precise manner. I hope that you can agree with it.
    – Christophe
    Commented Mar 4, 2020 at 8:36
  • The model is a piece of data ... it doesn't really call functions or receive function calls
    – Martin K
    Commented Mar 4, 2020 at 20:20

2 Answers 2

2

The View knows about the model and can call its properties, fields and methods as required. Not sure if you would call that "receive function calls"?

The Model doesn't know about the view so can't call it directly

The Controller knows about the Model and the View and can affect both, although its usual not to call the view directly.

2
  • Not it's clear to me. thank you Mr. @Ewan
    – dextoruz
    Commented Mar 4, 2020 at 6:01
  • 1
    It might be worth adding that while the View can access the Model, it should do so only in a read-only manner. The View is not allowed/supposed to make changes to the Model. Commented Mar 4, 2020 at 10:30
2

There are several flavors of MVC.

In the original concept published 1979, the view queries the model and the model doesn’t know about the views. However constant polling is not so efficient.

Subsequent MVC designs therefore generally see the view as an observer of the model. This means that views subscribe to the model and get notified of changes. The model does not know that it’s a view and can not use the full view’s interface. You’ll find an in-depth analysis of the MVC relationships in GoF (page 4 to 6).

4
  • For the ignorant but interested: What's GoF?
    – Aganju
    Commented Mar 4, 2020 at 4:21
  • @Aganju Oh! Sorry! GoF stands for "Gang of Four". It refers to the seminal book "Design patterns" by Gamma, Helm, Johnson & Vlissides (the 4 authors). I added a hyperlink in my answer to clarify.
    – Christophe
    Commented Mar 4, 2020 at 6:58
  • If you mention "several flavors of MVC", don't forget the "web flavor", where there is no connection between the Model and the View and all interaction goes via the Controller. Commented Mar 4, 2020 at 10:33
  • @BartvanIngenSchenau very good remark! In fact this is was the driving factor behind Talligent’s MVP architecture, the P being this pass-through controller
    – Christophe
    Commented Mar 4, 2020 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.