官术网_书友最值得收藏!

MVVM

MVVM stands for Model-View-View-Model. It is similar to the MVC model, the only difference being it has two-way data binding with the view and view-model. The changes in the view are being propagated via the view-model, which uses an observer pattern to communicate between the view-model and the model. The view in this case is completely isolated from the model.

The major advantage of using MVVM is it enables automatic changes in the view via the view-model:

Figure 2.2.3

MVVM has the following components:

  • Model: The model represents the objects in the application. This has the logic of where the data is to be fetched from.
  • View: The view is similar to the MVC pattern view, which renders information to users and contains a UI Component .xml file, activity, fragments, and dialog under the View Layer. It does not have any other logic implemented.
  • View-model: The view-model helps in maintaining the state of the view and does changes to the model based on the inputs gained from the view.

Many views can be linked to one view-model, which creates a many-to-one relation between the view and a view-model. Also, a view has information about the view-model but the view-model does not have any information about the view. The view is not responsible for the state of information; rather, that is being managed by the view-model and the view and the model are only reflected via the changes made to the view-model.

In developer's terminology, one can say that the view-model is the interface between a designer and a coder.

主站蜘蛛池模板: 贡嘎县| 合阳县| 比如县| 蕉岭县| 奈曼旗| 桂东县| 石狮市| 夹江县| 蚌埠市| 达孜县| 延津县| 洛川县| 顺平县| 齐齐哈尔市| 绥德县| 新民市| 上杭县| 浦东新区| 新安县| 遵义县| 凤山市| 教育| 阿尔山市| 漳州市| 漾濞| 南涧| 海伦市| 蒙山县| 卢氏县| 金溪县| 保德县| 孟连| 徐闻县| 安化县| 拜泉县| 横山县| 靖安县| 育儿| 洪江市| 南汇区| 浠水县|