“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层吗?
其他回答
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层应用程序。
从技术上讲,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层”应用程序。
:)
层只是应用程序中职责功能分离的代码类型(例如,表示,数据,安全等)。
层指的是代码的逻辑分离。逻辑层帮助您更好地组织代码。例如,应用程序可以具有以下层。
表示层或UI层 业务层或业务逻辑层 数据访问层或数据层
上述三个层驻留在它们自己的项目中,可能是3个项目,甚至更多。当我们编译这些项目时,我们得到了相应的层DLL。现在我们有3个dll了。
根据我们部署应用程序的方式,我们可能有1到3层。因为我们现在有3个DLL,如果我们将所有DLL部署在同一台机器上,那么我们只有1个物理层,但有3个逻辑层。
如果我们选择将每个DLL部署在单独的机器上,那么我们就有3层和3层。
层是逻辑上的分离,层是物理上的分离。我们也可以说层是层的物理部署。
层是应用程序内相关功能[代码]的逻辑分离,层之间的通信是显式和松散耦合的。[表示逻辑,应用逻辑,数据访问逻辑]
层是在单个计算机(进程)中[托管在单个服务器上]的层的物理分离。
如图所示:
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等单独的设备添加多个显示层]
来自博客的图表
层是概念实体,用于从逻辑角度分离软件系统的功能;当你实现系统时,你使用不同的方法组织这些层;在这种情况下,我们不称它们为层,而是称它们为层。
推荐文章
- “Layers”和“Tiers”的区别是什么?
- 一般来说,在一个组件中使用一个还是多个useEffect钩子更好?
- 何时以及如何在微服务架构中使用GraphQL
- 服务应该总是返回dto,还是也可以返回域模型?
- “协程”和“线程”之间的区别?
- 当Node.js内部仍然依赖线程时,它是如何固有地更快的?
- 允许PHP应用程序使用插件的最佳方法
- 会话锁导致ASP。网络网站速度慢
- 基于组件的游戏引擎设计
- 如何防止网站刮取?
- 软件设计与软件体系结构
- 领域驱动设计:领域服务、应用服务
- INotifyPropertyChanged vs. ViewModel中的DependencyProperty
- 什么是数据传输对象(DTO)?
- 为什么IoC / DI在Python中不常见?