“Layers”和“Tiers”的区别是什么?


当前回答

Logical layers are merely a way of organizing your code. Typical layers include Presentation, Business and Data – the same as the traditional 3-tier model. But when we’re talking about layers, we’re only talking about logical organization of code. In no way is it implied that these layers might run on different computers or in different processes on a single computer or even in a single process on a single computer. All we are doing is discussing a way of organizing a code into a set of layers defined by specific function. Physical tiers however, are only about where the code runs. Specifically, tiers are places where layers are deployed and where layers run. In other words, tiers are the physical deployment of layers.

来源:Rockford Lhotka,所有应用程序都应该是n层吗?

其他回答

当你谈论表示、服务、数据、网络层时,你是在谈论层。 当你“分别部署它们”时,你谈论的是层。

Tiers是关于部署的。 这样说吧:我们有一个应用程序,它有一个用Angular创建的前端,它有一个像MongoDB一样的后端,还有一个在前端和后端之间交互的中间层。因此,当前端应用程序、数据库应用程序和中间层都单独部署时,我们称其为3层应用程序。

好处:如果我们将来需要扩展后端,我们只需要独立地扩展后端,而不需要扩展前端。

层指的是代码的逻辑分离。逻辑层帮助您更好地组织代码。例如,应用程序可以具有以下层。

表示层或UI层 业务层或业务逻辑层 数据访问层或数据层

上述三个层驻留在它们自己的项目中,可能是3个项目,甚至更多。当我们编译这些项目时,我们得到了相应的层DLL。现在我们有3个dll了。

根据我们部署应用程序的方式,我们可能有1到3层。因为我们现在有3个DLL,如果我们将所有DLL部署在同一台机器上,那么我们只有1个物理层,但有3个逻辑层。

如果我们选择将每个DLL部署在单独的机器上,那么我们就有3层和3层。

层是逻辑上的分离,层是物理上的分离。我们也可以说层是层的物理部署。

Logical layers are merely a way of organizing your code. Typical layers include Presentation, Business and Data – the same as the traditional 3-tier model. But when we’re talking about layers, we’re only talking about logical organization of code. In no way is it implied that these layers might run on different computers or in different processes on a single computer or even in a single process on a single computer. All we are doing is discussing a way of organizing a code into a set of layers defined by specific function. Physical tiers however, are only about where the code runs. Specifically, tiers are places where layers are deployed and where layers run. In other words, tiers are the physical deployment of layers.

来源:Rockford Lhotka,所有应用程序都应该是n层吗?

为什么总想用复杂的词?

一层=你的代码的一部分,如果你的应用程序是一个蛋糕,这是一片。

一层=一台物理机器,一台服务器。

一个层承载一个或多个层。


层的例子:

表示层=通常是所有与用户界面相关的代码 数据访问层=与数据库访问相关的所有代码

层:

你的代码托管在服务器上=你的代码托管在一个层上。

你的代码托管在2个服务器上=你的代码托管在2层上。

例如,一台机器承载Web站点本身(表示层),另一台机器更安全地承载所有更安全的代码(真正的业务代码-业务层、数据库访问层等)。


实现分层架构有很多好处。这很棘手,正确实现分层应用程序需要时间。如果你有一些,看看微软的这篇文章:http://msdn.microsoft.com/en-gb/library/ee658109.aspx

阅读Scott Hanselman关于这个问题的帖子:关于“三/多层/层架构/设计”的提醒:

请记住,在“Scott的世界”(希望也是你的世界:)中,“Tier”是一个部署单元,而“Layer”是代码中责任的逻辑分离。你可能会说你有一个“三层”系统,但在一台笔记本电脑上运行它。你可能会说你有一个“三层”系统,但只有ASP。与数据库对话的NET页。精准就是力量,朋友们。