读 Patterns of Enterprise Application Architecture 1

 

Layering is an important technique, but there are downsides.

  • Layers encapsulate some, but not all, things well. As a result you sometimes get cascading changes. The classic example of this in a layered enterprise application is adding a field that needs to display on the UI, must be in the database, and thus must be added to every layer in between.

  • Extra layers can harm performance. At every layer things typically need to be transformed from one representation to another. However, the encapsulation of an underlying function often gives you efficiency gains that more than compensate. A layer that controls transactions can be optimized and will then make everything faster.

But the hardest part of a layered architecture is deciding what layers to have and what the responsibility of each layer should be.

 

层用来封装下层的,但不一定是完全的封装。封装数据结构会让层与层之间不得不,进行数据表达的转换,但封装行为确是会为这样的附加工作量得到补偿。到底该如何封装呢?
但最难确定是并不是这个,而是层化架构中的每一个层有什么,应该负责什么。

When people discuss layering, there's often some confusion over the terms layer and tier. Often the two are used as synonyms, but most people see tier as implying a physical separation. Client杝erver systems are often described as two-tier systems, and the separation is physical: The client is a desktop and the server is a server. I use layer to stress that you don't have to run the layers on different machines. A distinct layer of domain logic often runs on either a desktop or the database server. In this situation you have two nodes but three distinct layers. With a local database I can run all three layers on a single laptop, but there will still be three distinct layers.

层(layer) 与 层级(tier) 有点区别,可能用中文比较难以区分。都可以翻译成层次。很多人把 tier 理解成指物理上的分离。我们用layer 特指逻辑上的 分离层次。他们可以任意运行在一个或多个(物理)平台上

Three Principal Layers

Layer

Responsibilities

Presentation

Provision of services, display of information (e.g., in Windows or HTML, handling of user request (mouse clicks, keyboard hits), HTTP requests, command-line invocations, batch API)

Domain

Logic that is the real point of the system

Data Source

Communication with databases, messaging systems, transaction managers, other packages


以上是 martin fowler  所说的j2ee层次架构中 的三主要层次。presentation layer 就是与ui交互的部分。domain layer是核心逻辑部分。Data Source layer 是指于其它系统交互的部分。对于Data Source layer在实际情况中,其去很大一部分就是与数据库交互,所以对于与数据库等进行持久化操作的的Data Source layer有时也叫做 persistence layer。
这个模式只是 martin fowler等人的看法。其实,还有其他模式可以参考。比如:四层架构模式 (Four Layer Architecture) 六角形架构模(Hexagonal Architecture) 式等等。个人观点:我个人认为作为应用系统高级目标更倾向于六角形架构模式,而martin他们提出的模式,更适用于现在web应用或以使用人为核心应用系统的情况。个人感觉其缺乏普遍性。
http://c2.com/cgi/wiki?HexagonalArchitecture
http://c2.com/cgi/wiki?FourLayerArchitecture

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wfeng007/article/details/371216
个人分类: 构架
相关热词: patterns
上一篇业务逻辑层 重点分类(随)
下一篇csdn的blog没有文章导入功能么?
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭