DialogFragments 应该有自己的 ViewModel 还是应该使用包含 Fragment 的 ViewModel?

Should DialogFragments have their own ViewModel or should they use the ViewModel of their containing Fragment?

我是 android 的新手,我不确定让 DialogFragments 使用其包含的 Fragment 的 ViewModel 是否是一个好的做法,或者它是否应该有自己的 ViewModel。

我问这个是因为 Google 建议每个 Activity/Fragment 都有自己的 ViewModel。

我没有发现对话框有自己的 ViewModel 有什么问题。这将属于单一职责原则,其中片段仅处理与其相关的内容,DialogFragment 也是如此。尝试让它们不耦合。

https://en.wikipedia.org/wiki/Single_responsibility_principle