控制器在MVC设计模式 [英] Controller in MVC design pattern

查看:139
本文介绍了控制器在MVC设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下在MVC中为什么我们需要controller.why我们不直接连接模型和查看。如果我们没有控制器会是什么问题?

解决方案

分离问题,使程序更易维护,并允许我们在系统的不同部分添加更多功能,而不会破坏其他部分因为彼此独立...
https://en.wikipedia.org / wiki / Separation_of_concerns



所以如果你的域的代码和如何给予视图的逻辑,然后处理演示的代码屏幕上的数据都在一个地方,它使您很难更改域代码的部分,而无需更改将其移动到视图的逻辑部分以及随后显示的代码。与控制器,我们可以将逻辑移动到另一个类,使其独立于视图,所以当我们修复或修改我们的应用程序时,我们只需要关心一部分MVC模型...


I want to ask that in MVC why do we need controller.why don't we just directly connect model and view.what would be the problem if we don't have controller ?

解决方案

Separation of concerns, it makes the program more maintainable and allows us to add more functionality to different parts of the system without breaking other parts because they are independant of each other... https://en.wikipedia.org/wiki/Separation_of_concerns

So if your code for your domain and the logic of how it should be given to the view and then the code which handles the presentation of the data on the screen are all in the one place it makes it very hard for you to change parts of the domain code without having to change parts of the logic which moves it to the view and also the code which then presents it..with the controller we can move the logic into another class and make it independent of the view so when we are fixing or modifying our application we only need to concern ourselves with one part of the MVC model...

这篇关于控制器在MVC设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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