我在哪里可以找到MVC的明确例子?

时间:2022-12-22 11:27:32

I've read a couple of things about MVCs but I still don't understand when they should be used and when they shouldn't be used. I am looking for clear examples that say things like "if you're developing this then you should use MVC, like this" and "if you're developing this, you shouldn't use MVC." Most of the examples I've seen rely on complex frameworks which have already implemented everything and you have to learn the framework and use it a lot to understand what's really happening. To many programmers, phrasings such as "UI business logic" sound like marketing terms — for example, the words "Instead the View binds directly to a Presentation Model" are used in this post.

我已经阅读了一些关于MVC的内容,但我仍然不明白何时应该使用它们以及什么时候不应该使用它们。我正在寻找明确的例子,说“如果你正在开发这个,那么你应该使用MVC,就像这样”和“如果你正在开发它,你不应该使用MVC。”我见过的大多数例子都依赖于已经实现了所有内容的复杂框架,你必须学习框架并使用它来了解真正发生的事情。对于许多程序员来说,诸如“UI业务逻辑”之类的措辞听起来像营销术语 - 例如,在这篇文章中使用了“而不是视图直接绑定到表示模型”。

I am aware of the dangers that may lurk in the shadows as MVC is a concept and everyone feels like they know it best, yet nobody really knows exactly how to use it because there may be a lot of variables involved and everyone is allowed to have a different perspective on how to dissect a project into the Model, the View and the Controller. There is a lot of theory out there but very few clear examples. What I'm looking for are not "the best" ways of doing it so this should not be considered as subjective; I'm looking for different simple implementations that would allow me to decide on my own which are the best approaches.

我知道可能潜伏在阴影中的危险,因为MVC是一个概念,每个人都觉得他们最了解它,但没有人真正知道如何使用它,因为可能涉及很多变量,每个人都被允许拥有关于如何将项目分解为模型,视图和控制器的不同观点。有很多理论,但很少有明确的例子。我正在寻找的不是“最好”的方式,所以这不应该被认为是主观的;我正在寻找不同的简单实现,这将允许我自己决定哪种是最好的方法。

Succinctly: What are good on-line resources that present pro and con arguments to using MVC in various situations and provide clear examples to help the reader understand the concept?

简洁地说:什么是良好的在线资源,提供在各种情况下使用MVC的赞成和反对论据,并提供明确的例子来帮助读者理解这个概念?

6 个解决方案

#1


13  

IMO, the best examples are with code and/or starter kits.

IMO,最好的例子是代码和/或入门套件。

Rob Conery has a great number of posts that explain how to to create an MVC site with ASP.NET MVC. Each one of these has a video tutorial which runs through the blog post discussion.

Rob Conery有很多帖子解释了如何使用ASP.NET MVC创建MVC站点。其中每个都有一个视频教程,贯穿博客文章讨论。

The official ASP.NET MVC site also has some video posts, starter kits (here, here and here) and extra sauce to help.

官方的ASP.NET MVC网站也有一些视频帖子,入门套件(这里,这里和这里)和额外的酱汁来帮助。

IMO, MVC is the way to go for Web Sites. Without spewing all the jargon and marketing speak, it really breaks down your code into nice, separate and defined sections. Each of these sections can also be tested .. which really helps protect the development process because you have peace of mind knowing that touching one part of the system doesn't break another (because the tests all pass after your latest change).

IMO,MVC是网站的方式。没有喷出所有的行话和营销说话,它确实将你的代码分解为漂亮,独立和定义的部分。这些部分中的每一部分也可以进行测试..这确实有助于保护开发过程,因为您可以放心地知道触摸系统的一部分不会破坏另一部分(因为测试都会在您最近的更改后通过)。

Other blogs which you should check out:

您应该查看的其他博客:

#2


4  

Assuming you mean MVC for the web you'd be hard pressed to find anything more concise than the following 60 lines of code:

假设您的网络意味着MVC,您将很难找到比以下60行代码更简洁的内容:

http://code.google.com/p/barebonesmvc-php/

In particular note the sendResponse "template method", which in turn is essentially comprised of the following 2 method calls:

特别注意sendResponse“模板方法”,它又基本上由以下2个方法调用组成:

applyRequestToModel

applyModelToView

#3


2  

One of the heighest rated that I've seen is the the Learn MVC in 7 days post. Of course, as good as it is, it still pales in comparison to a book like Pro ASP.NET MVC 4

我见过的最高评价之一是7天后的学习MVC。当然,尽管它很好,但与Pro ASP.NET MVC 4这样的书相比仍然相形见绌

#4


1  

I have done this every which way for various projects. From coding everything for an application in one great big PHP script (OK it started as a small PHP script which just grew). To using the latest greatest Spring/Freemarker framework where my 5O lines of java code were lost in a sea of XML and template coding.

我已经为各种项目的每一个方式做了这个。从一个伟大的PHP脚本编写应用程序的所有内容(好吧,它开始是一个刚刚增长的小PHP脚本)。使用最新的最好的Spring / Freemarker框架,我的5行java代码在XML和模板编码的海洋中丢失了。

You can do MVC without a framework, and, in php this is probably the simplest way. If all your navigation code is in a single script with only navigation logic then you are doing MVC!

你可以在没有框架的情况下做MVC,而在php中这可能是最简单的方法。如果您的所有导航代码都在一个只有导航逻辑的脚本中,那么您正在进行MVC!

For anything other than a QDP (Quick Dirty Page) I would recommend using some sort of MVC. Just imagine what you would need to do if the business said "can I have a French language version" or "great program but I want to store the data in xxxxx database".

除了QDP(Quick Dirty Page)以外的任何其他内容,我建议使用某种MVC。想象一下,如果企业说“我可以拥有法语版本”或“优秀程序但我想将数据存储在xxxxx数据库中”,您需要做什么。

#5


1  

there are some flavours of mvc: http://en.wikipedia.org/wiki/Presentation-abstraction-control, http://en.wikipedia.org/wiki/Model_View_Presenter.

有一些风格的mvc:http://en.wikipedia.org/wiki/Presentation-abstraction-control,http://en.wikipedia.org/wiki/Model_View_Presenter。

also see: http://c2.com/cgi/wiki/like?ModelModelViewController

另见:http://c2.com/cgi/wiki/like?ModelModelViewController

related question: Examples of Hierarchical-Model-View-Controller (HMVC)?

相关问题:分层模型 - 视图 - 控制器(HMVC)的例子?

#6


0  

Its often hard to clearly separate your view logic with your business logic. If you read up abit on JSF & JSP examples you can see clear examples of MVC in use. Completely seperating the view from the business logic.

通常很难将您的视图逻辑与业务逻辑明确区分开来。如果您阅读了JSF和JSP示例的abit,您可以看到正在使用的MVC的明确示例。从业务逻辑中完全分离视图。

If your looking for good information about MVC I can suggest http://en.wikipedia.org/wiki/Model-view-controller

如果您正在寻找有关MVC的好信息,我可以建议http://en.wikipedia.org/wiki/Model-view-controller

This is an important topic and I really like the idea of sepperating the different logics. It helps the programmer and everyone else working on the project.

这是一个重要的主题,我非常喜欢分离不同逻辑的想法。它可以帮助程序员和其他所有从事该项目的人。

#1


13  

IMO, the best examples are with code and/or starter kits.

IMO,最好的例子是代码和/或入门套件。

Rob Conery has a great number of posts that explain how to to create an MVC site with ASP.NET MVC. Each one of these has a video tutorial which runs through the blog post discussion.

Rob Conery有很多帖子解释了如何使用ASP.NET MVC创建MVC站点。其中每个都有一个视频教程,贯穿博客文章讨论。

The official ASP.NET MVC site also has some video posts, starter kits (here, here and here) and extra sauce to help.

官方的ASP.NET MVC网站也有一些视频帖子,入门套件(这里,这里和这里)和额外的酱汁来帮助。

IMO, MVC is the way to go for Web Sites. Without spewing all the jargon and marketing speak, it really breaks down your code into nice, separate and defined sections. Each of these sections can also be tested .. which really helps protect the development process because you have peace of mind knowing that touching one part of the system doesn't break another (because the tests all pass after your latest change).

IMO,MVC是网站的方式。没有喷出所有的行话和营销说话,它确实将你的代码分解为漂亮,独立和定义的部分。这些部分中的每一部分也可以进行测试..这确实有助于保护开发过程,因为您可以放心地知道触摸系统的一部分不会破坏另一部分(因为测试都会在您最近的更改后通过)。

Other blogs which you should check out:

您应该查看的其他博客:

#2


4  

Assuming you mean MVC for the web you'd be hard pressed to find anything more concise than the following 60 lines of code:

假设您的网络意味着MVC,您将很难找到比以下60行代码更简洁的内容:

http://code.google.com/p/barebonesmvc-php/

In particular note the sendResponse "template method", which in turn is essentially comprised of the following 2 method calls:

特别注意sendResponse“模板方法”,它又基本上由以下2个方法调用组成:

applyRequestToModel

applyModelToView

#3


2  

One of the heighest rated that I've seen is the the Learn MVC in 7 days post. Of course, as good as it is, it still pales in comparison to a book like Pro ASP.NET MVC 4

我见过的最高评价之一是7天后的学习MVC。当然,尽管它很好,但与Pro ASP.NET MVC 4这样的书相比仍然相形见绌

#4


1  

I have done this every which way for various projects. From coding everything for an application in one great big PHP script (OK it started as a small PHP script which just grew). To using the latest greatest Spring/Freemarker framework where my 5O lines of java code were lost in a sea of XML and template coding.

我已经为各种项目的每一个方式做了这个。从一个伟大的PHP脚本编写应用程序的所有内容(好吧,它开始是一个刚刚增长的小PHP脚本)。使用最新的最好的Spring / Freemarker框架,我的5行java代码在XML和模板编码的海洋中丢失了。

You can do MVC without a framework, and, in php this is probably the simplest way. If all your navigation code is in a single script with only navigation logic then you are doing MVC!

你可以在没有框架的情况下做MVC,而在php中这可能是最简单的方法。如果您的所有导航代码都在一个只有导航逻辑的脚本中,那么您正在进行MVC!

For anything other than a QDP (Quick Dirty Page) I would recommend using some sort of MVC. Just imagine what you would need to do if the business said "can I have a French language version" or "great program but I want to store the data in xxxxx database".

除了QDP(Quick Dirty Page)以外的任何其他内容,我建议使用某种MVC。想象一下,如果企业说“我可以拥有法语版本”或“优秀程序但我想将数据存储在xxxxx数据库中”,您需要做什么。

#5


1  

there are some flavours of mvc: http://en.wikipedia.org/wiki/Presentation-abstraction-control, http://en.wikipedia.org/wiki/Model_View_Presenter.

有一些风格的mvc:http://en.wikipedia.org/wiki/Presentation-abstraction-control,http://en.wikipedia.org/wiki/Model_View_Presenter。

also see: http://c2.com/cgi/wiki/like?ModelModelViewController

另见:http://c2.com/cgi/wiki/like?ModelModelViewController

related question: Examples of Hierarchical-Model-View-Controller (HMVC)?

相关问题:分层模型 - 视图 - 控制器(HMVC)的例子?

#6


0  

Its often hard to clearly separate your view logic with your business logic. If you read up abit on JSF & JSP examples you can see clear examples of MVC in use. Completely seperating the view from the business logic.

通常很难将您的视图逻辑与业务逻辑明确区分开来。如果您阅读了JSF和JSP示例的abit,您可以看到正在使用的MVC的明确示例。从业务逻辑中完全分离视图。

If your looking for good information about MVC I can suggest http://en.wikipedia.org/wiki/Model-view-controller

如果您正在寻找有关MVC的好信息,我可以建议http://en.wikipedia.org/wiki/Model-view-controller

This is an important topic and I really like the idea of sepperating the different logics. It helps the programmer and everyone else working on the project.

这是一个重要的主题,我非常喜欢分离不同逻辑的想法。它可以帮助程序员和其他所有从事该项目的人。