Can a model observe?

I am developing a Java application, in my GUI I have several JPanelswith a lot of settings for them, it will be View . In the background of these few JPanelsthere is only one Model . Normally, I would observe a Model from JPanels.

I'm just wondering, it's good practice to observe the View from the Model ? Because the user changes the View , and this change should affect my Model . Or did I miss some important principle here? Thank you for your help.

+3
source share
3 answers

I think it's great that you ask about it.

What part you are missing that might help is the controller.

See http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller for an example.

Basically, the controller mediates between the model and the view. He "Manages" the application. The only thing your eye needs to know is the data that is passed to it and how to display it. The only thing your model needs to know is data. The controller links the two together and contains business logic that acts on the data and prepares it for viewing.

What you get from using this project is a loosely coupled and easily verifiable application. This is really elegant IMHO.

,

Mike

+6

. , .

, ​​- , , , -? - , . , . . ? , .

+2

, , , - , Model-View-Controller. , .

Model-View-Presenter. , . -View - ( , ).

+1

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


All Articles