如何在“模型-视图-控制器"中设计模型的接口? [英] How to design the interface for the Model in Model-View-Controller?

查看:61
本文介绍了如何在“模型-视图-控制器"中设计模型的接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解MVC模式是如何工作的,但是我一直有这个问题.如果您有一个大型模型,其中有许多委派给各个类的函数,那么是否必须使用所有用于操纵和查询模型的方法来定义大型整体接口?

I understand how the MVC pattern works, but I've always had this question. If you have a big Model with many functions delegated to various classes, do you have to define a big monolithic interface with all the methods to manipulate and query the Model?

或者,可以将该模型划分为多个模型,彼此对话,然后可以使用其各自的控制器对其进行操作吗?

Or, can that model be partitioned to many models, that talk to each other, and then you can manipulate them with their respective controllers?

谢谢

推荐答案

"ViewModel"概念在这里可能会有所帮助-Phil Haack在"

The "ViewModel" concept may be helpful here -- it's also referred to as "view specific model" by Phil Haack in the book "Professional ASP.NET MVC3".

许多自动工具生成器或脚手架"生成器都希望创建单个页面/界面,但是没有什么可以阻止您对大型模型进行多阶段处理.

A lot of auto-tooling or "scaffolding" generators look to create a single page/interface but there is nothing preventing you from making a multi-stage process for a large model.

一个选择是为流程的每个阶段创建视图模型(即BigProcessPartAViewModel,BigProcessPartBViewModel等),然后生成一个控制器,使用单独的视图来处理每个模型.显然,您需要跨多个阶段管理状态,可能需要使用数据库或会话.

One option would be to create View Models for each stage of the process (ie. BigProcessPartAViewModel, BigProcessPartBViewModel, etc) and then generate a controller that process each of these with separate views. Obviously you'll need to manage state across multiple stages, perhaps with a database or session.

此外,您的模型就是您的模型……这不是数据访问.因此,您可能需要具有处理过程中状态的附加模型以及允许多阶段事务的数据访问设计.

Additionally, your model is your model... it is NOT data access. So you may need to have an additional model that handles in-process state as well as a data access design that allows for a multi-phase transaction.

这篇关于如何在“模型-视图-控制器"中设计模型的接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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