MVC应用程序。如何MULT层体系结构适合吗? [英] MVC application. How does mult-tier architecture fit in?

查看:130
本文介绍了MVC应用程序。如何MULT层体系结构适合吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的MVC,多层次的Web架构的概念。我开发PHP应用程序和正在使用可用的MVC框架之一。我的问题是:

I am new to the concept of MVC and multi-tiered web architecture. I developing a PHP application and am using one of the available MVC frameworks. My question is as follows:

据我了解,在MVC本身不被视为一个多层架构。我能理解如何使用MVC单是采取非结构化方式的一个步骤,但我正在考虑一个简单的三层架构将如何适应?将MVC驻留在presentation层?什么是添加一种分层的方法的优劣?从我收集,用MVC单独有没有明确的数据对象负责从数据库中检索数据,这通常被塞进模型。同样的商业逻辑,它在一个3层架构将驻留在业务层(或任何你想将它命名),可以塞进控制器。

From what I understand, MVC in and of itself is not considered a multi-tier architecture. I can understand how using MVC alone is a step up from taking an unstructured approach, but I was contemplating how a simple 3-tier architecture would fit in? Would MVC reside in the presentation layer? What are the merits of adding a tiered approach? From what I gather, with MVC alone there are no explicit data objects responsible for retrieving data from the database and this is usually stuffed into the model. Likewise the business logic, which in a 3-tiered architecture would reside in a 'business-layer' (or whatever you want to call it), can be stuffed into the controller.

我的理解有点是否正确?我知道我问了很多问题,但是我想听听你讨论如何引入n层架构到MVC框架(PHP或其他),因为我认为两者并不相互排斥。谢谢!

Is my understanding somewhat correct? I know I asked a lot of questions, but I would like to hear you discuss how you incorporated an n-tier architecture into your MVC framework (PHP or otherwise) as I assume that the two are not mutually exclusive. Thanks!

推荐答案

M)M是你的模型。这通常是生活在业务层或只是背后的presentation层的层。很多人不喜欢presentation层具有业务层的任何知识,但并让他们进一步抽象,通过其所谓的视图模型。这些频繁的DTO(数据传输对象)松散地映射到你的域模型。对我来说(.NET的家伙)有工具,如AutoMapper使来自域模型转换为视图模型。

M) M is your model. This is generally living in your business layer or the layer just behind your presentation layer. Many people don't like the presentation layer to have any knowledge of the business layer though and so they further abstract that by having what is called a ViewModel. These frequently are DTO (data transfer objects) that loosely map to your Domain model. For me (.net guy) there are tools such as AutoMapper to make the conversion from Domain Model to View Model.

V)V是你的看法。该视图是presentation层。这是实际的HTML或PHP code用户直接接触和互动。该视图应尽可能轻(意味着没有逻辑如果可能的话)。尽量保持任何形式的,如果/然后输入场景出来的观点,坚持只显示和收集数据。 present一个ViewModel你的网页设计师,使他们不会污染你的DomainModel。

V) V is your view. The view is your presentation layer. This is the actual HTML or PHP code that the user directly touches and interacts with. The view should be as light as possible (meaning no logic if possible). Try to keep any sort of if/then type scenarios out of the view and stick to just displaying and collecting data. Present a ViewModel to your web designers so that they don't contaminate your DomainModel.

c)c是控制器。这很像一个统筹。它从您的视图数据,并确保它得到正确的后端函数/方法处理这些数据。它也从它的方式向前端后端坐标数据

C) C is your controller. This is much like a co-ordinator. It takes data from your view and makes sure it gets to the right back end function/method for processing that data. It also co-ordinates data from the back end on it's way to the front end.

其中多层的设计理念进来是presentation层后面(哪里是哪里MVC主要是)。当控制器从视图中获取数据并将其传递回后端(如果你按照国内长途或领域驱动设计)将数据传递到应用程序服务(即负责统筹后端事宜类)。该服务可以将数据进一步推到存储库层(这是讲数据库,文件系统,网络服务等一类 - 任何基础设施的东西)。 DDD是一个很大的话题,但会得到解决的n层的方法你的头和它如何与MVC的作品。

Where multi-tier design concepts come in is behind the Presentation layer (where is where MVC is primarily). When the controller is taking data from the view and passing it back to the back end it (if you follow DDD or Domain Driven Design) would pass the data to an application service (a class that co-ordinates back end matters). The service might further push the data into a Repository layer (which is a class that speaks to the database, filesystem, web services, etc. - any infrastructure stuff). DDD is a big topic but will get your head around the n-tier approach and how it works with MVC.

在研究这个课题看看IOC(控制反转),DI(依赖注入),TDD(测试驱动开发),并尽可能多的方式尽可能(门面,工厂等)。

While researching this topic take a look at IoC (inversion of control), DI (dependency injection), TDD (test driven development), and as many patterns as possible (facade, factory, etc.).

这篇关于MVC应用程序。如何MULT层体系结构适合吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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