谁负责下一个视图? [英] Who's responsible for the next View?

查看:124
本文介绍了谁负责下一个视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个典型的MVC架构师中,逻辑在哪里,决定了下一个显示哪个视图?



假设是某种具有多个视图(Windows)的应用程序,根据用户操作可能在不同时间可能看不到或可能不可见。例如,有时候,应用程序可能需要用户填写附加细节的表单,其他时候可能不会。控制者有责任要求一个特定的视图变得可见吗?



我在想这个错误?也许控制器确定哪个控制器应该控制,视图只是根据哪个控制器活动更新?



我很困惑。

解决方案

控制器是MVC模式的老板。它负责委托,而自己做最小的工作;)。



一个请求进来,老板看着它,并认为Hrm ...这里有很多工作,我需要从我的数据库中获取一些数据幸运的是,我有下属!嘿,模型,来到这里,我需要你离开并获得DAL的所有信息。



将模型视为开发商。所有真正的努力工作,让他的手脏,没有模型,整个系统会崩溃。它脱离了所有的业务和域逻辑。然后它回到老板手中,全力以赴。 这里你去gov。



老板然后需要将数据返回给用户。再次 - 为他工作太多了。所以他得到了一个愚蠢的小辈开发商,也是这样做的观点。 (不是所有的小辈都是愚蠢的,但它适用于这个例子!)。视图什么也不知道。它不关心数据如何发生,只是它在那里和工作。老板可能会对数据进行一些细微改动,因为我们不希望视图的负担超过需要,所以视图会关闭并显示数据。根据工作量,老板可以招聘多个职位视图。



基本上控制器控制MVC模式中的所有流。它决定要调用哪些模型,以及要呈现的视图,以及模型中要传递给视图(ViewModels)的数据。



您可以从控制器调用其他控制器。如果您的主页上有一个搜索框,例如,当用户点击搜索时,它可以调用搜索控制器上的索引函数。在我上面的比喻中,它将类似于一个部门将工作交给另一个部门。然后,这个整个过程再次开始,老板招聘当前需求的员工。


In an archetypical MVC architectur, where does the logic go, that determines which view to show next?

The assumption is some kind of app with several views (windows) that may or may not be visible at different times, depending on user actions. For instance, sometimes the application may need the user to fill out a form with additional details, other times it may not. Is it the controllers responsibility to ask for a specifik view to become visible?

Am I thinking about this wrong? Maybe the controller determines which other controller should assume control, and the view just updates according to which controller is active?

I'm confused.

解决方案

The controller is the boss in the MVC pattern. It is responsible for delegation whilst doing minimal work itself ;).

A request comes in and the boss looks at it and thinks "Hrm... there is a lot of work involved here. I need to get some data from my database. Luckily I have subordinates! Hey model, come over here. I need you to go off and get all the information form the DAL."

Think of the model as a developer. Does all the real hard work, gets his hands dirty, and without the model, the whole system would come crashing down. It goes off and does all the business and domain logic. It then runs back to the boss and hands in all his hard work. "Here you go gov".

The boss then needs to return the data to the user. Again - too much work for him. So he gets a stupid junior dev aka the view to do it. (Not all juniors are stupid, but it works for this example!). The view knows nothing. It doesn't care how the data came to be, just that it's there and works. The boss may make some minor alterations to the data as we don't want the view having more responsibility than it needs, then the view goes off and displays the data. Depending on the work load, the boss may recruit multiple views for the job.

Basically the controller controls all flow in the MVC pattern. It decides what models to call, and what views to render, and what data from the model to pass to the view (ViewModels).

You can call other controllers from a controller. If you have a search box on your homepage for example, when a user hits search, it can call the index function on the search controller. In my metaphor above, it would be akin to one department passing a job to another department. Then this whole process starts again, with the boss recruiting the staff he needs for the current request.

这篇关于谁负责下一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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