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


当前回答

我发现一个定义说,层是逻辑分离,层是物理分离。

其他回答

In plain english, the Tier refers to "each in a series of rows or levels of a structure placed one above the other" whereas the Layer refers to "a sheet, quantity, or thickness of material, typically one of several, covering a surface or body". Tier is a physical unit, where the code / process runs. E.g.: client, application server, database server; Layer is a logical unit, how to organize the code. E.g.: presentation (view), controller, models, repository, data access. Tiers represent the physical separation of the presentation, business, services, and data functionality of your design across separate computers and systems. Layers are the logical groupings of the software components that make up the application or service. They help to differentiate between the different kinds of tasks performed by the components, making it easier to create a design that supports reusability of components. Each logical layer contains a number of discrete component types grouped into sublayers, with each sublayer performing a specific type of task.

两层模式表示客户机和服务器。

在此场景中,客户机和服务器可能存在于同一台机器上,也可能位于两台不同的机器上。下图演示了一个常见的Web应用程序场景,其中客户机与位于客户机层的Web服务器交互。该层包含表示层逻辑和任何所需的业务层逻辑。Web应用程序与承载数据库层的独立机器通信,数据库层包含数据层逻辑。

分层的优点:

Layering helps you to maximize maintainability of the code, optimize the way that the application works when deployed in different ways, and provide a clear delineation between locations where certain technology or design decisions must be made. Placing your layers on separate physical tiers can help performance by distributing the load across multiple servers. It can also help with security by segregating more sensitive components and layers onto different networks or on the Internet versus an intranet.

1层应用程序可以是3层应用程序。

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

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

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

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

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

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

我喜欢下面来自微软应用程序架构指南2的描述

层描述了应用程序中功能和组件的逻辑分组;而层描述了功能和组件在独立服务器、计算机、网络或远程位置上的物理分布。尽管层和层使用相同的名称集(表示、业务、服务和数据),但请记住,只有层意味着物理分离。

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层吗?

Yes my dear friends said correctly. Layer is a logical partition of application whereas tier is physical partition of system tier partition is depends on layer partition. Just like an application execute on single machine but it follows 3 layered architecture, so we can say that layer architecture could be exist in a tier architecture. In simple term 3 layer architecture can implement in single machine then we can say that its is 1 tier architecture. If we implement each layer on separate machine then its called 3 tier architecture. A layer may also able to run several tier. In layer architecture related component to communicate to each other easily. Just like we follow given below architecture

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

客户端可以与“表示层”进行交互,但出于安全考虑,客户端可以访问“业务逻辑层”下一层的公共组件(如业务逻辑层的公共组件)。 问:为什么我们使用层结构? 因为如果我们实现了层结构,我们就能提高应用程序的效率

= = >安全

= = >可管理性

= = >可伸缩性

其他需求,如开发应用程序后,我们需要改变DBMS或修改业务逻辑等,那么这是必要的。

问:为什么我们要使用分层架构?

因为每一层的物理实现都提供了更好的效率,没有层架构我们就无法实现层架构。分离机实现分离 层和分离层是实现一个或多个层这就是我们使用它的原因。 它用于容错目的。 ==>易于维护。

简单的例子

就像银行开在一个房间里,员工在里面分类:

门房 现金的人 负责介绍银行方案的人 经理

它们都是系统的相关组件。

如果我们去银行贷款,首先是一个门卫微笑着开门 之后我们就去就近介绍所有贷款方案的人 我们去经理小屋,通过贷款。 在那之后,最后我们去收银台贷款。 这些是银行的层结构。

层级呢? 一家银行的分行开在一个城镇,接着又开在另一个城镇,接着又开在另一个城镇 但是每个分支的基本要求是什么呢

门房 现金的人 负责介绍银行方案的人 经理

层和层的概念完全一样。