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

本文是小编为大家收集整理的关于什么是MVC,它的优势是什么?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我找到了什么是MVP和MVC,什么是差异,但并没有真正回答这个问题.

我最近开始使用MVC,因为它是我自己和我的工作伙伴将要使用的框架的一部分.我们之所以选择它,是因为它看起来很容易且分开的过程与显示,除此之外,还有我们不知道并且可能错过的优势吗?

pros

  1. 显示和处理分开


cons

  1. 到目前为止,没有

推荐答案

mvc是 m odel的分离, v iew和 c ontroller-仅此而已.这只是一个范式;设计课程时,您应该在脑海中拥有的理想.避免将三个类别的代码混合到一个类中.

例如,虽然表格网格 view 显然应显示一旦显示的数据,但它不应具有从何处检索数据或其本机结构的代码( <> /em>)就像.同样,虽然它可能具有总结列的函数,但实际求和应该在 Controller .

中发生.

a"保存文件"对话框( view )最终通过用户挑选的路径到达 Controller ,然后询问 model 用于数据,并进行实际保存.

这种责任的分离允许在道路上灵活.例如,由于视图不在乎基础模型,因此支持多个文件格式更容易:只需为每个模型添加一个模型子类.

其他推荐答案

关注点的分离是大的.

能够分开这些组件使代码更易于重复使用和独立测试.如果您实际上不知道MVC是什么,请谨慎尝试了解人们的意见,因为仍然对"模型"有一些争议(无论是业务对象/数据集/数据表还是代表基础服务层).

我已经看到了各种各样的实现,这些实现自称为MVC,但并非完全,并且作为 Jeff的文章显示MVC是一个有争议的观点,我认为开发人员永远不会完全同意.

所有不同MVC类型的良好综述都可以在这里.

其他推荐答案

Jeff有 post 关于它,否则我找到了一些useful documents on Apple's website, in Cocoa tutorials (this one例如).

本文地址:https://www.itbaoku.cn/post/627524.html

问题描述

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

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?

Pros

  1. Display and Processing are seperated


Cons

  1. None so far

推荐答案

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.

其他推荐答案

Separation of concerns is the biggy.

Being able to tease these components apart makes the code easier to re-use and independently test. If you don't actually know what MVC is, be careful about trying to understand people's opinions as there is still some contention about what the "Model" is (whether it is the business objects/DataSets/DataTables or if it represents the underlying service layer).

I've seen all sorts of implementations that call themselves MVC but aren't exactly and as the comments in Jeff's article show MVC is a contentious point that I don't think developers will ever fully agree upon.

A good round up of all of the different MVC types is available here.

其他推荐答案

Jeff has a post about it, otherwise I found some useful documents on Apple's website, in Cocoa tutorials (this one for example).