一个模型实体,多个页面

编程入门 行业动态 更新时间:2024-10-27 21:15:15
本文介绍了一个模型实体,多个页面 ->多个视图?多个视图模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

由于屏幕空间有限,我将使用多个页面(连续显示 - 思考向导)捕获单个实体的用户输入.在我的模型中,我希望将此实体建模为单个类是正确的.

Due to limited screen real estate I will be capturing user input for a single entity using multiple pages (displayed consecutively - think wizard). In my model I expect it is correct to model this entity as a single class.

在 MVVM 实现中,我假设将每个页面视为单独的视图是 MVVM 的最佳实践.这是正确的吗?

In an MVVM implementation I am assuming it is best MVVM practice to consider each page as a seperate View. Is this correct?

对于每个 Page 是否都有自己的 ViewModel 或者是否应该有一个 ViewModel 实例被多个 Pages 引用的最佳 MVVM 实践是否有共识?

举例说明:

选项 1

Class A (X, Y, Z) ViewModelA1 (X) ViewModelA2 (Y) ViewModelA3 (Z) View1 captures ViewModelA1 View2 captures ViewModelA2 View3 captures ViewModelA3

选项 2

Class A (X, Y, Z) ViewModelA (X, Y, Z) View1 captures ViewModelA.X View2 captures ViewModelA.Y View3 captures ViewModelA.Z

推荐答案

查看"这个词说明了一切.这是数据的视图.ViewModel 的工作是使来自模型的数据具有可展示性.任何需要对数据执行的操作都发生在视图模型中,以便视图可以显示它.

The word "View" says it all. It's a view of the data. The ViewModel's job is to make the data coming from the model presentable. Whatever needs to be done to the data happens in the viewmodel so that the view can show it.

通常情况下,您的视图与视图模型之间是一对一的关系,因为通常您只想以一种方式显示该数据.(一个视图")我偏离常规做法(可能是 MVP 模式?)的地方在于,如果您想以多种不同的方式显示数据(例如您想要条形图或折线图或饼图)和数据所有视图都相同,那么您只需要一个视图模型.它是 DRY 原则的一个例子.如果您有三个视图模型并且它们都相同,则使用一个视图模型.多个视图.一个视图模型.

Normally you will have a one to one relationship of you view to viewmodels, because normally you only want to show that data in one way. (one "view") Where I deviate from the normal practice (possibly from MVP pattern?) is that if you want to show the data in a number of different ways (for example you want a bar graph or a line graph, or a pie chart) and the data is the same for all of the views then you only need one viewmodel. Its a case of the DRY principle. If you have three viewmodels and they are all the same, then use one viewmodel. Multiple Views. One viewmodel.

更多推荐

一个模型实体,多个页面

本文发布于:2023-05-31 10:09:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/389609.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   实体   模型   页面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!