“Layers”和“Tiers”的区别是什么?
当前回答
我喜欢下面来自微软应用程序架构指南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层吗?
阅读Scott Hanselman关于这个问题的帖子:关于“三/多层/层架构/设计”的提醒:
请记住,在“Scott的世界”(希望也是你的世界:)中,“Tier”是一个部署单元,而“Layer”是代码中责任的逻辑分离。你可能会说你有一个“三层”系统,但在一台笔记本电脑上运行它。你可能会说你有一个“三层”系统,但只有ASP。与数据库对话的NET页。精准就是力量,朋友们。
我使用层来描述我的解决方案组件中的架构师或技术堆栈。通常在涉及网络或进程间通信时,我使用层对这些组件进行逻辑分组。
从技术上讲,Tier可以是代码运行所需的一种最小环境。
例如,假设一个3层应用程序可以运行
3 physical machines with no OS . 1 physical machine with 3 virtual machines with no OS. (That was a 3-(hardware)tier app) 1 physical machine with 3 virtual machines with 3 different/same OSes (That was a 3-(OS)tier app) 1 physical machine with 1 virtual machine with 1 OS but 3 AppServers (That was a 3-(AppServer)tier app) 1 physical machine with 1 virtual machine with 1 OS with 1 AppServer but 3 DBMS (That was a 3-(DBMS)tier app) 1 physical machine with 1 virtual machine with 1 OS with 1 AppServers and 1 DBMS but 3 Excel workbooks. (That was a 3-(AppServer)tier app)
Excel工作簿是运行VBA代码所需的最低环境。
这3个工作簿可以放在一台物理计算机上,也可以放在多个物理计算机上。
我注意到,在实践中,人们在应用描述上下文中说“层”时,指的是“操作系统层”。
也就是说,如果一个应用运行在3个不同的操作系统上,那么它就是一个3层应用。
所以从学究角度来说,描述应用程序的正确方法是
“1至3层能力,运行在2层”应用程序。
:)
层只是应用程序中职责功能分离的代码类型(例如,表示,数据,安全等)。
层是应用程序内相关功能[代码]的逻辑分离,层之间的通信是显式和松散耦合的。[表示逻辑,应用逻辑,数据访问逻辑]
层是在单个计算机(进程)中[托管在单个服务器上]的层的物理分离。
如图所示:
1-Tier & 3-Layers « App Logic with out DB access store data in a files.
2-Tier & 3-Layers « App Logic & DataStorage-box.
2-Tier & 2-Layers « Browser View[php] & DataStorage[procedures]
2-Tier & 1-Layers « Browser View[php] & DataStorage, query sending is common.
3-Tier & n-Layer « Browser View[php], App Logic[jsp], DataStorage
n层优势: 更好的安全性 可伸缩性:随着组织的发展,您可以使用DB-Clustering扩展您的DB-Tier,而不涉及其他层。 可维护性:Web设计人员可以更改视图代码,而无需触及其他层上的其他层。 轻松升级或增强[例如:您可以添加额外的应用程序代码,升级存储区域,甚至为移动,平板电脑,pc等单独的设备添加多个显示层]
来自博客的图表