读 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值