讀 Patterns of Enterprise Application Architecture 1

來源:互聯網
上載者:User

 

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.