什么是MVC,它的优点是什么? [英] What is MVC and what are the advantages of it?

查看:127
本文介绍了什么是MVC,它的优点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现什么是mvp和mvc以及什么是差异,但它并没有真正回答这个问题。

I found What are mvp and mvc and what is the difference but it didn't really answer this question.

我最近开始使用MVC,因为它是我自己和我的工作的框架的一部分伙伴将要使用。我们选择它是因为它看起来容易和分离的过程与显示,除了我们不知道和可能会错过的有什么优势吗?

I've recently started using MVC because it's part of the framework that myself and my work-partner are going to use. We chose it because it looked easy and separated process from display, are there advantages besides this that we don't know about and could be missing out on?

优点


  1. 显示和处理分开



缺点


  1. 目前为止


推荐答案

MVC是分离 m odel, v < b> iew和 c ontroller - 没有更多的东西了。这只是一个范例在设计课程时,您应该拥有的理想。避免将三个类别的代码混合成一个类。

MVC is the separation of model, view and controller — nothing more, nothing less. It's simply a paradigm; an ideal that you should have in the back of your mind when designing classes. Avoid mixing code from the three categories into one class.

例如,一个表格格式视图应该显示出一次显示的数据,应该没有从哪里检索数据的代码,或其原生结构(模型)是什么样的。同样,虽然它可能有一个函数来总结列,但实际求和应该在控制器中发生。

For example, while a table grid view should obviously present data once shown, it should not have code on where to retrieve the data from, or what its native structure (the model) is like. Likewise, while it may have a function to sum up a column, the actual summing is supposed to happen in the controller.

文件'对话框(视图)最终将路径(一旦被用户选择)传递到控制器,然后向模型请求数据,并实际保存。

A 'save file' dialog (view) ultimately passes the path, once picked by the user, on to the controller, which then asks the model for the data, and does the actual saving.

这种责任分离允许灵活性下降。例如,由于视图不关心底层模型,支持多种文件格式更容易:只需为每个文件添加一个模型子类。

This separation of responsibilities allows flexibility down the road. For example, because the view doesn't care about the underlying model, supporting multiple file formats is easier: just add a model subclass for each.

这篇关于什么是MVC,它的优点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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