gpt4 book ai didi

Android 的 ViewModel 和 MVVM

转载 作者:太空宇宙 更新时间:2023-11-03 10:36:11 33 4
gpt4 key购买 nike

有一种称为MVVM(模型- View - View 模型)的设计模式,其中使用 View 模型作为 View 的抽象。 View Model 应该向 View 公开数据流并与 Model 的数据交互。

但是有一个ViewModel Android 框架中的类。


问题:Android 的 ViewModel与 MVVM 模式中的 View 模型有关吗?

最佳答案

它们是不同的。 Android 所指的 ViewModel 就是。

The ViewModel class is designed to store and manage UI-related data so that the data survives configuration changes such as screen rotations.

MVVM 模式需要 View、ViewModel 和 Model。在 View 和 ViewModel 之间发生绑定(bind)。

Android ViewModel 与 UIController 交互,几乎只是 UI 的状态保持,而不是遵循 MVVM 模式。

关于Android 的 ViewModel 和 MVVM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44224688/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com