MVC、MVP、MVVM 等用户界面设计模式中的模型是什么?

发布于 2024-10-10 08:05:01 字数 265 浏览 0 评论 0原文

我看过很多使用模型-视图 UI 设计模式的教程和示例,它们的实现方式都非常不同,尤其是模型部分。在某些示例中,模型是数据(某些数据库的实际对象表示),在某些示例中,模型是数据访问层(如存储库模式),在某些示例中,模型是服务层...
如果有人告诉您他在他的应用程序中使用 MV* 模式,那么它会告诉您有关应用程序设计的哪些信息?它是否在对象图中维护数据库的内存表示,并将其用作数据源或某些数据访问层来查询数据库...

您将选择什么作为主要包含带表的选项卡页的面向数据的智能客户端应用程序的模型?

I have seen lots of tutorials and examples using Model-View UI design patterns, and they all implement them pretty differently, especially the Model part. In some examples Model is data (actual object representation of some DB) in some it's data access layer (like repository pattern) in some it's service layer...
If someone tells you he is using MV* pattern in his app, what will it tell you about app design? Does it maintain in-memory representation of database in object graph and use it as data source or some data access layer to query data base...

What you will choose as a Model for data oriented smart client app containing mostly Tab Pages with Tables?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

幸福%小乖 2024-10-17 08:05:01

模型一词至少有两种含义。这是您的域模型。这里的意义是你如何表示你的数据。构建数据的方法有很多种,访问数据的方法也有很多种。当我们在这个意义上谈论模型时,我们并不特别关心如何访问构成模型的结构,即数据访问或持久层,尽管您也可能听到人们谈论持久性模型。人们指的是持久性实现所使用的特定理念,例如 ActiveRecord 或 Repository。您可能还会听说这些被称为模式。

最后,模型这个词在 MVC、MVP 和 MVVM 的视图上下文中具有非常具体的含义。在该上下文中,它意味着与视图(视图模型)关联的特定数据对象。这可能是域对象之一,但更常见的是,它是特定于视图的对象,封装来自一个或多个域对象的数据以及辅助数据,例如特定视图使用的用户数据。

对于您的应用程序,选择最适合您的开发环境和语言的持久性模型 - MS 世界中的 LINQ to SQL、LINQ to Entities、nHibernate、Castle ActiveRecord 等 为每个视图创建特定于视图的模型(类)保存该视图所需的数据。使用控制器查询域模型以提取视图所需的信息并将其映射到视图模型上。

The word model is used in, at least, two senses. There is your domain model. Here the sense is how you represent your data. There are many ways to structure your data and also many ways to access it. When we talk about the model in this sense we're not particularly concerned with how you are accessing the structures that make it up, i.e., the data access or persistence layer, although you may also hear people speak of the model of persistence. By this, people mean the particular philosophy that the persistence implementation uses, such as ActiveRecord or Repository. You might also hear these referred to as patterns.

Finally, the word model has a very specific meaning in MVC, MVP, and MVVM in the context of a view. In that context it means that particular data object associated with a view, the view model. This could be one of your domain objects, but more typically it is a view-specific object that encapsulates data from one or more domain objects along with ancillary data such as user data that is used by a particular view.

For your application, choose the persistence model that best suits your development environment and language -- LINQ to SQL, LINQ to Entities, nHibernate, Castle ActiveRecord, etc. in the MS world Create view-specific models (classes) for each of your views that hold the data needed by that view. Use your controllers to query your domain model to extract the information needed by the view and map that onto the view model.

谜兔 2024-10-17 08:05:01

如果有人说,他正在使用 MV* 模式,则意味着应用程序被分成几个部分,在不直接引用特定类型的情况下进行操作,它没有说明任何有关实际实现的信息。 MVVM 意味着,你有一个模型、一个视图模型和视图部分,仅此而已。

该模型是您的数据存储。这并没有说明它的实现,它可以是任何东西,具体取决于手头的任务。但是,应该使用接口来访问它,这样您就可以快速交换实现。从某种意义上说,这就是 MVVM 模式的全部要点 - 通过接口解耦三层。

您的描述听起来很像我目前的项目 - 我使用 sqlite 作为后备存储,并使用实体框架作为 ORM。但是,我还使用 T4 生成 Dto 对象,然后通过 ViewModel 中的自动映射器进行映射,因为这些对象只需要数据,而不需要持久性。

If someone says, he is using MV* pattern, it means the application is split into several parts, acting without a direct reference to a specific type, it doesn't say anything about the actual implementation. MVVM means, you have a Model, a ViewModel and View part, that's all.

The model is your data storage. This doesn't say anything of the implementation of it, it can be anything, depending on the task at hand. However, it should be accessed using interfaces, so you can quickly exchange the implementation. That, in a sense, is the whole point of the MVVM pattern - decoupling of the three tiers via interfaces.

Your description sounds alot like my project at the moment - I use sqlite as backing storage with Entity Framework as ORM. However, I also use T4 to generate Dto objects which then get mapped via automapper in the ViewModel, as those only need the data, not the persistance.

巴黎夜雨 2024-10-17 08:05:01

该模型通常指的是数据层,但正如我发现的,在 MVC 中,在实现 ntier 方法时,这可能会有点误导。其原因是模型未包含在其自己的装配体中。

以下是我对类似问题得到的一些非常有用的反馈对 MVC 和实体模型的混淆< /a>

The model typically refers to the data layer, but as I discovered, in MVC this can be a little msleading when implementing an ntier approach. The reason for this is that the model is not contained in it's own assembly.

Here is some of very useful feedback I got to a similar question Confussion over MVC and entity model

野鹿林 2024-10-17 08:05:01

模型可以被视为数据容器,其有助于呈现呈现组件和/或将数据保存到数据源(即数据库等)/从数据源(即数据库等)保存数据。除了数据容器元素之外,模型可能包含也可能不包含行为,具体取决于相应架构的设计上下文。

虽然术语“模型”在模型-视图-控制器模式上下文中经常讨论和使用,但它是当前软件架构领域最重要的考虑因素之一。

您可能需要查看以下内容 文章 其中很少有与演示组件和模型相关的流行和新的设计模式描述的。

A model can be considered as data container that facilitates rendering presentation component and/or persisting data to/from data source (i.e. database etc). Besides the data container elements, a model may or may not contain behavior, depending on design context of corresponding architecture.

While the term “Model” is frequently discussed and used in Model-View-Controller pattern context, it is one of most important consideration in current world of software architecture

You may want to look the following article where few popular and new design patterns that are related to presentation component and model are described.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文