Model view controller

I have a control tree in my GUI (with a natural set of GUI / platform functions for processing nodes).
I have a data model with my own set of nodes, children, properties, etc.

I want the tree to display the representation of the model, allow me to send messages to nodes within the model, and I was told to redraw itself when the model changes.

But I don’t want the GUI code to need the details of the model data types, and I don’t want to pollute the model by linking it to GUI classes.

I can’t understand how the controller should do this and what functions should it provide?

(this is in C ++, but it doesn't matter)

+3
source share
6 answers

"GUI controls" are not entirely suitable for the model controller template, because they usually have their own internal model, rather than accepting a link to it. If the structure is structured this way, you will need an adapter class that "binds data" to the internal control model to the underlying data model.

This can do something similar to what would be with the model controller, except that the adapter class plays the role of both a connection component for viewing (updating the GUI from the data model) and the controller (interpreting GUI events in the model actions) .

+2
source
+1

:

  • .

, , - . , , .

- . , . , , , .

(, , ..). , , . . , , , .

+1

, . "" "" MVC. GUI ( ). ​​

" " - , . , , GUI " ".

" " . "" "".

+1

:. " " , . , , , , .

: , . . ,

: MVP. . , , .. - . Presenter.

+1

, , ( MFc CTreeView/CTreeCtrl - Qt), .
- gui.

set/get . , gui.

Updating the model’s presentation form requires sending a message if you don’t want the model to know about your gui messages, the best you can do is register the callback function (void pointer to the function) from the tree controller - and name it to perform the update . This update function can then query the model for changes.

0
source

Source: https://habr.com/ru/post/1702167/


All Articles