MVVM没有用于临时事物的模型可以吗? [英] Is it ok to have MVVM without model for temporary things?

查看:60
本文介绍了MVVM没有用于临时事物的模型可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从架构的角度来看,您认为拥有ViewModel-无需模型的视图来处理临时性的东西还可以吗?

Do you think it is alright from architectural stand-point to have ViewModel - View without Model for temporary things?

例如:我希望用户输入一些路径,以便以后可以打开一些文件.对于我来说,仅将路径存储在ViewModel的任何地方对我来说都是没有意义的,当用户单击显示所有文件"时,我随后以某种方式构造文件的模型和用于View的ViewModels. 因此,实际上我唯一的模型是文件的模型.

E.g.: I want users to input some paths so I can open some files later on. It doesn't make sense for me to store the paths anywhere just ViewModel and when the user clicks "Show all files" I then construct models of the files and ViewModels for View that represent them somehow. So really my only model is the model of the file.

推荐答案

我认为有时人们会将设计和架构模式误认为是硬性规定和快速规定.我们需要了解,这些只是指导原则.一个例子就是不同的编程语言实现单例模式的方式.

I think sometimes people mistake design and architectural patterns as hard and fast rules. We need to understand that these are just guidelines. One example of this could be the way different programming languages implement singleton pattern.

因此,我想说的是,如果您需要将View Model的功能绑定到View,但实际上不需要模型,则忽略模型应该没有任何问题.我建议将这些模式用作指导原则,而不是一成不变的规则.随时在适当的地方进行细微的调整.

So I would say if you need the functionality of View Model to be bound to View but really don't require a model, there shouldn't be any problem in ignoring the model. I would suggest use these patterns as guidelines and not as hard and fast rules. Feel free to make minor adjustments wherever applicable.

但是同时请记住,您没有违反创建这些层的目的.它不会像我们绕过模型并直接从View Model开始查询后端数据库那样发生.只要坚持关注点分离的基本原则,一切都应该很好.

But at the same time keep in mind that you are not violating the purpose with which these layers are created. It should not happen like we bypass the model and start querying the backend database directly from the View Model. As long as the basic principle of separation of concerns is adhered to everything should be fine.

这篇关于MVVM没有用于临时事物的模型可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆