“Layers”和“Tiers”的区别是什么?
当前回答
为什么总想用复杂的词?
一层=你的代码的一部分,如果你的应用程序是一个蛋糕,这是一片。
一层=一台物理机器,一台服务器。
一个层承载一个或多个层。
层的例子:
表示层=通常是所有与用户界面相关的代码 数据访问层=与数据库访问相关的所有代码
层:
你的代码托管在服务器上=你的代码托管在一个层上。
你的代码托管在2个服务器上=你的代码托管在2层上。
例如,一台机器承载Web站点本身(表示层),另一台机器更安全地承载所有更安全的代码(真正的业务代码-业务层、数据库访问层等)。
实现分层架构有很多好处。这很棘手,正确实现分层应用程序需要时间。如果你有一些,看看微软的这篇文章:http://msdn.microsoft.com/en-gb/library/ee658109.aspx
其他回答
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层应用程序。
阅读Scott Hanselman关于这个问题的帖子:关于“三/多层/层架构/设计”的提醒:
请记住,在“Scott的世界”(希望也是你的世界:)中,“Tier”是一个部署单元,而“Layer”是代码中责任的逻辑分离。你可能会说你有一个“三层”系统,但在一台笔记本电脑上运行它。你可能会说你有一个“三层”系统,但只有ASP。与数据库对话的NET页。精准就是力量,朋友们。
我使用层来描述我的解决方案组件中的架构师或技术堆栈。通常在涉及网络或进程间通信时,我使用层对这些组件进行逻辑分组。
当你谈论表示、服务、数据、网络层时,你是在谈论层。 当你“分别部署它们”时,你谈论的是层。
Tiers是关于部署的。 这样说吧:我们有一个应用程序,它有一个用Angular创建的前端,它有一个像MongoDB一样的后端,还有一个在前端和后端之间交互的中间层。因此,当前端应用程序、数据库应用程序和中间层都单独部署时,我们称其为3层应用程序。
好处:如果我们将来需要扩展后端,我们只需要独立地扩展后端,而不需要扩展前端。
层是概念实体,用于从逻辑角度分离软件系统的功能;当你实现系统时,你使用不同的方法组织这些层;在这种情况下,我们不称它们为层,而是称它们为层。