爲什麼說應用架構需要分類思維?

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":"br"}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"簡介:","attrs":{}},{"type":"text","text":"如何定義架構?應用架構的要素有哪些?什麼是應用架構中的分類思維?開源應用架構COLA的作者張建飛介紹他在COLA架構設計中的一些思想經驗,分享他的應用架構之道。","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"模塊(Module)、組件(Component)、包(Package),這些概念對於我們技術同學並不陌生,但並不是所有人都能理解其要義。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"深入理解之後,我才發現,其背後的深意是分類思維。而這種分類也是應用架構的核心所在,通過不同粒度、不同層次的分類,把複雜的軟件系統實現控制在可以被理解、被維護的程度。否則,對於動則上100萬行代碼的軟件,人類根本沒有辦法理解和維護。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"試想一個極端情況,假如沒有這些概念協助我們分類,我們把所有業務邏輯都寫在一個類裏面,會是什麼樣的結果呢?我們很多的“非人類”系統,正是因爲沒有進行合理的分類造成的。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"早期,我不喜歡JavaScript的一個重要原因,正是因爲其缺少像Java中package和jar的概念,導致代碼的組織形式比較鬆散、隨意。這個問題直到ES6、React纔得到比較好的解決,在此之前,前端工程師不得不依靠seaJS,requireJS這些框架來做模塊化、組件化的事情。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"至此,你可能有疑問,分類有什麼魔力?怎麼就成了應用架構的核心了呢?客官彆着急,由我細細道來。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"分類的重要性","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"所謂分類,就是依據一定的標準對給定的事物進行組別的劃分。我們人類天生就有分類的本能,例如,當我們觀察下面這張圖的時候。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/22/22cceb767fff0b266798c420b36c9762.png","alt":"image.png","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"無論是誰,乍一看到上面的六個黑點,都會認爲共有兩組墨點,每組三個。造成這種印象的原因主要是,人類大腦會自動將發現的所有事物以某種持續組織起來。基本上,大腦會認爲同時發生的任何事物之間都存在某種關聯,並且會將這些事物按某種邏輯模式組織起來。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"之所以我們大腦有這樣的本能,是因爲人一次能夠理解的思想或概念的數量是有限的。正如喬治米勒在他的論文《奇妙的數字7》中提出的。人類大腦的短期記憶無法一次容納7個以上的記憶項目。所以,當信息量過大時,唯有歸類分組才能幫助我們去理解和處理問題。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"其實,自古及今,人類一直在做着歸類/分類,早在春秋時期,《戰國策》中就提出過“物以類聚,人以羣分”的概念。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在互聯網行業,我們會對客戶進行分類,然後針對不同的客戶進行分層運營,也是這個道理。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"平常我們所說的分析和綜合的背後,其實就是分類能力。分析是在一個類裏面找差異性,綜合是在不同事物中找聯繫、找共同性,而這個共同性相當於分類的維度。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"分類思維的能力,直接體現的就是看透事物本質的能力。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"應用架構中的分類思維","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"概念定義","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在討論架構之前,我們先來明確一下Module、Component和Package這幾個概念。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"因爲這些概念一直以來存在不小的歧義。通過Stack Overflow上幾十篇詢問這些概念差異的提問,以及五花八門的回答就能可見一斑。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在一篇Stack Overflow的帖子[1]中,我們看到這樣的回答:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"The terms are similar. I generally think of a \"module\" as being larger than a \"component\". A component is a single part, usually relatively small in scope, possibly general-purpose.","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"然而,另一篇Stack Overflow的帖子[2],卻有着不同的答案:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"There is no criteria to measure which one is greater than the other. One component can contain list of modules, and one module also can contain many components.","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在《實現領域驅動設計》一書中,作者有這樣的描述:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"If you are using Java or C#, you are already familiar with Modules, though you know them by another name. Java calls them packages. C# calls them namespaces.","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"然而,在AngularJS的設計文檔[3]中,它對Module和Component是這樣定義的:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"The module can be considered as a collection of components, Each component can use other components. One of many modules combines up to make an Application.","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/83/835ef5b3a8f34d925c50a19a0b21bdf6.png","alt":"image.png","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通過比較,結合我自己的認知,我更贊同AngularJS裏面的定義,即Module是比Component更大的概念。比如在Maven中,Module是組成Application的第一級層次,而Component的粒度一般比Module要小,多個Component會組成一個Module。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"因此,在進一步探討之前,我特意對這些概念做如下定義:","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"應用(Application):應用系統,有多個Module組成,用方框表示。","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"模塊(Module):一個Module是有一組Component構成,用正方體表示。","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"組件(Component):表示一個可以獨立提供某方面功能的物件,用UML的組件圖表示。","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"包(Package):Package相對比較tricky,它是一種組織形式,和粒度不是一個維度的,也就是說,一個Component可以包含多個Package,一個Package也可以包含多個Component。","attrs":{}}]}],"attrs":{}}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"基於上面的定義,他們的表示法(Notation)是這樣的:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/43/43430e13e6286f8a284803553062127a.png","alt":"image.png","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"應用架構的要素","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"關於架構的定義有很多,我最喜歡,也是最簡潔的定義是:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/83/832a4fda9c48e0d912cf81bd2d718c5c.png","alt":"image.png","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"即架構是一種結構,是由物件(Components)+ 物件之間的關係 + 指導原則組成的。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/80/80200c24e23c09c11d16639ead3ab1de.png","alt":"image.png","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對於後端開發來說,應用層是我們的主戰場,也是整個系統最複雜的部分(當然,前端也不簡單),所有的業務邏輯都匯聚在此。所以,對於應用層,我們需要進行進一步拆分,而不僅僅是在這裏寫業務邏輯就完事了。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對應用層的進一步分層,就形成了COLA所提倡的四層結構,對應到Maven中,就是有4個Module,編譯打包之後會有4個Jar。一個典型的應用,其Module呈現出如下的結構:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"\n cloudstore-adapter \n cloudstore-app \n cloudstore-domain \n cloudstore-infrastructure \n cloudstore-client \n start \n","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"當業務變得複雜時,這種分層結構自然比沒有分層要好。這也是COLA一直致力要去解決的問題——控制複雜度。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從COLA 1.0的事無鉅細,到COLA 3.0的化繁爲簡。我漸漸明白,COLA作爲應用架構,其核心不是去提供功能,而是提供基模(Archetype)。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在1.0的時候,COLA提供了Interceptor能力,提供了Event Bus能力,提供了擴展點能力。一個是我認爲大家“需要”這些,另一個是感覺NB的框架就應該面面俱到,沒有幾個高級功能都不好意思開源。事實證明,我犯了一個慣性錯誤——過度設計。Interceptor完全可以用AOP替代,內部事件和擴展點很少被用到。所以在COLA 3.0的時候,果斷的去掉了這些“雞肋”,只保留了擴展點功能。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"迴歸到架構的本質,COLA的核心應該是規定應用的結構和規範,即應用架構基模(Archetype)。而不是去糾結那些錦上添花的功能。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"升級到COLA 3.1","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"實際上,這樣的迴歸工作,COLA 3.0已經做的差不多了。在這次3.1的升級中,除了進一步去除了Event Bus的功能之外,最重要的就是重新規範了分包策略,和擴充了原來控制層(Controller)的職責。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"分包策略調整","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"分層是一種在功能維度上的橫向切分,即每一層都有自己的職責。","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Adapter層:路由用戶request + 適配response。","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"App層:接收請求,聯合domain層一起做業務處理。","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Domain層:領域模型 + 領域能力。","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Infrastructure層:技術細節(DB,Search,RPC..) + 防腐(Anti-corruption)。","attrs":{}}]}],"attrs":{}}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"分層處理沒有問題,只是這種功能劃分,會帶來一個問題,即領域維度的內聚性會收到影響。當一個application只負責一個領域的時候沒有問題。然而,當一個application包含多個業務領域的時候,這種內聚性缺失的弊端就比較明顯了。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"更好的分包策略是按領域劃分,而不是按功能。因爲,領域更內聚,功能是爲領域服務的,應該歸屬於領域。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"然而,不巧的是,在COLA應用架構裏面,我們要綜合橫向功能維度的劃分,和縱向領域維度的劃分,兩個都很好,兩個都想要。怎麼辦?我們可以採用物理劃分和邏輯劃分相結合的辦法。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c1/c19286244617ff0614dc2a203eba5997.png","alt":"image.png","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/3c/3c91364384f5d8c88ef1b81826ee61e7.png","alt":"image.png","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"按照領域的分包策略至少會帶來兩個好處:","attrs":{}}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"系統的可理解性和可維護性更好,用白話說,就是找東西更好找了。","attrs":{}}]}],"attrs":{}},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"方便以後的拆分,比如下單域(Order)變得越來越複雜,需要拆出去,我們只需要把Order下面的東西遷移到一個新應用就好了。","attrs":{}}]}],"attrs":{}}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"用Adatper代替Controller","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Controller這個名字主要是來自於MVC,因爲是MVC,所以自帶了Web應用的烙印。然而,隨着mobile的興起,現在很少有應用僅僅只支持Web端,通常的標配是Web,Mobile,WAP三端都要支持。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在這樣的背景下,狹義的控制層已經不能滿足需求了,因爲在這一層,不僅僅要做路由轉發,還要做多端適配,類似於六邊形架構中的Driving Adapter的角色。鑑於此,我們使用適配層(Adapter)替換掉了Controller,一方面,是爲了呼應六邊形架構;另一方面,的確也是需要做多端適配。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"基於這樣的變化,我重構了COLA Archetype,把Adapter作爲一個層次凸顯出來。實際上,Infrastructure也是適配器,是對技術實現的適配(或者叫解耦),比如,我需要數據來幫助構造Domain Entity,但是我不care這個數據是來自於DB、RPC還是Search,或者說,我可以在這些技術實現中進行自由切換,而不影響我Domain層和App層的穩定性。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"改造後的COLA在架構風格,模塊、組件以及分包策略上都會有所調整,具體變化請參考下面兩張圖。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/7f/7f18e6e2d89b68a19c7d46c26075ec32.png","alt":"image.png","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"COLA3.1","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"COLA組件關係圖:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/a6/a6b56f1c5547b2d69b73186c146658b6.png","alt":"image.png","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"組織架構中的分類思維","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這麼重要的思維能力,其應用肯定不僅僅侷限於架構設計的範疇。開篇已經說過了,分類是我們人類的本能,是分析和綜合問題的重要手段。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"生產關係決定生產力,好的組織結構會助力業務發展,反之,則會拖業務的後退。因此,大公司的CEO每年都會花很多時間在組織設計上,這也是爲什麼,在大廠,每年我們都會看到不小的組織調整。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/e8/e87db700025dc54694704ceca6e7af5a.png","alt":"image.png","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ab/ab5da14454a25c1453ae843c88b07540.gif","alt":null,"title":"點擊並拖拽以移動","style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"有沒有感覺蘋果的組織架構,和我們的COLA思想是一樣的:),物理上,按照職能劃分;邏輯上,按照業務和產品劃分。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"蘋果這樣的組織設計,是因爲它是技術和創新驅動的公司,協作成本不是最大的問題,缺少專業性(技術不行),缺少創新纔是攸關生死的大問題。所以他寧肯犧牲協同效率,也要確保專業性,也就是說,做攝像頭的只做攝像頭,做iOS的只做iOS,技術leader直接向CEO彙報,可以決定產品的發展方向。因爲他們在這個領域更專業。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"很早以前,史蒂夫·喬布斯就有這樣的觀點:蘋果公司的經理們應該是他們管理領域的專家。在 1984 年的一次採訪中,他說:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們在蘋果經歷了那個階段,當時我們出去想,哦,我們要成爲一家大公司,讓我們僱傭專業的管理人員。我們出去僱了一羣專業的管理人員。一點也不管用……他們知道如何管理,但他們在專業方面什麼都不知道。如果你是一個偉大的人,爲什麼你想爲一個你什麼都學不到的人工作?你知道什麼是有趣的嗎?你知道誰是最好的經理嗎?他們是偉大的個人貢獻者,他們從來都不想成爲一名管理者,但卻決定自己必須成爲,因爲沒有其他人能夠出色地完成工作。","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"說實話,看完這篇文章,我很感慨,一方面是佩服喬布斯的洞見能力,另一方面也爲我們這個行業感到唏噓,業務技術也是技術啊,卻沒有一個像樣的培育發展技術的環境和土壤。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如今,業務技術Leader還有多少是專注在技術上呢,儼然都變成了業務Leader。如果技術Leader都變成了純管理者,那麼誰去關心技術,誰去關心代碼,誰去關心工程師的成長呢?","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"分類學是科學也是藝術","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最後,我還是要中庸一下,分類很重要,但同時也很難,帶有一定的主觀性。就像比爾.布萊森在《萬物簡史》裏說的:","attrs":{}}]},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"分類學有時候被描述成一門科學,有時候被描述成一種藝術,但實際上那是一個戰場。即使到了今天,那個體系比許多人認爲的還要混亂。以描述生物基本結構的門的劃分爲例。許多生物學家堅持認爲總數30個門,但有的認爲20來個門,而愛德華在《生命的多樣性》一書裏提出的數字高達令人喫驚的89門。","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們觀察事物的視角不同,對問題的認知程度不同,得出來的分類也會不同。就拿COLA來說,直到現在的3.1版本,我個人認爲其分層和分包的方式才相對比較合理。然而,很有可能在後期的迭代中,分類方式又會改變。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"組織架構的分類方式也是一樣,按照業務和職能劃分,都可以。關鍵看其分類是否匹配你組織的特性,沒有最好的分類,只有最合適的。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除了本文分享的分類思維,更多的思維能力還可以參看作者的新書:《代碼精進之路:從碼農到工匠》。這是一本爲專業程序員而寫的書,主要分爲技藝、思想和實踐三個部分,詳細介紹了編程技巧和方法論、抽象能力、分治思想、常見的應用架構模式,以及COLA架構的設計原理。希望能夠幫助廣大程序員培養良好的編程習慣和思維。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"推薦閱讀","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://links.jianshu.com/go?to=https%3A%2F%2Fblog.csdn.net%2Fjavachengzi%2Farticle%2Fdetails%2F108219072","title":null},"content":[{"type":"text","text":"爲什麼阿里巴巴的程序員成長速度這麼快?","attrs":{}}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://links.jianshu.com/go?to=https%3A%2F%2Fblog.csdn.net%2Fjavachengzi%2Farticle%2Fdetails%2F110126069","title":null},"content":[{"type":"text","text":"霸榜GitHub的Offer來了原理篇+框架篇,開放分享;","attrs":{}}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://links.jianshu.com/go?to=https%3A%2F%2Fwww.bilibili.com%2Fvideo%2FBV1f541157DX%2F","title":null},"content":[{"type":"text","text":"50W年薪程序員需要的技術棧分析","attrs":{}}]}]},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"看完三件事❤️","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果你覺得這篇內容對你還蠻有幫助,我想邀請你幫我三個小忙:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"點贊,轉發,有你們的 『點贊和評論』,纔是我創造的動力。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"關注公衆號 『 Java鬥帝 』,不定期分享原創知識。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"同時可以期待後續文章ing🚀","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章