Spring的設計哲學和個人見解

Design Philosophy

When you learn about a framework, it’s important to know not only what it does but what principles it follows. Here are the guiding principles of the Spring Framework:

當你學習框架的時候,不僅知道它是怎麼運作的,而且知道它伴隨這什麼樣的原理,這是非常重要的。這裏有Spring框架的指導原理:

  • Provide choice at every level. Spring lets you defer design decisions as late as possible. For example, you can switch persistence providers through configuration without changing your code. The same is true for many other infrastructure concerns and integration with third-party APIs.在每個層次提供選擇。Spring允許您儘可能延遲設計決策。例如,在不改變你的代碼的情況下,通過配置來切換持久化提供程序。對於其他許多的下層基礎考慮和第三方api集成同樣是成立的。

  • Accommodate diverse perspectives. Spring embraces flexibility and is not opinionated about how things should be done. It supports a wide range of application needs with different perspectives.容納不同的觀點。Spring擁抱靈活性並且對於事情應該如何處理並不會固執己見。它支持各種不同角度的應用程序需求。

  • Maintain strong backward compatibility. Spring’s evolution has been carefully managed to force few breaking changes between versions. Spring supports a carefully chosen range of JDK versions and third-party libraries to facilitate maintenance of applications and libraries that depend on Spring.維護強有力的向後兼容。Spring的發展經過精心的管理,幾乎沒有在版本之間進行破壞性的更改。Spring支持精心選擇的JDK版本和第三方庫,以促進依賴於Spring的應用程序和庫的維護。

  • Care about API design. The Spring team puts a lot of thought and time into making APIs that are intuitive and that hold up across many versions and many years.關心API設計。Spring團推花費了大量的心思和時間在API設計上,這些API是直觀的,並且很多經得住版本迭代和歲月推移。

  • Set high standards for code quality. The Spring Framework puts a strong emphasis on meaningful, current, and accurate javadoc. It is one of very few projects that can claim clean code structure with no circular dependencies between packages.對代碼質量設置高標準。Spring框架強調有意義的、當前的、並且準確的java文檔。這是爲數不多的項目之一,它要求在包之間沒有循環依賴清晰的代碼結構。

以上出自Spring的文檔的Spring Framework Overview

對於第一點而言,Spring確實在各個層次能夠整合其他框架,使之發揮更強大的能量,比如在持久層,能夠整合MyBatis框架,學過MyBatis都知道,它幾乎消除了JDBC中的代碼、設置參數和手動獲取結果集的工作,使用簡單的XML配置文件,將POJO和數據庫中的表關聯起來。博採衆長,這也是Spring如今炙手可熱的原因之一吧。

對於第三點,我們知道有向前兼容和向後兼容,一般程序能夠向後兼容,這點真的稱不上爲哲學。

第四點有點吹水成分了,不過確實良好的API造福的是廣大Spring使用者。

第五點真是難得,Spring框架的IoC和AOP就能大大地減低程序的耦合性,其本身還自我要求,Spring自己的代碼之間清晰、沒有之間的依賴,真的是像成績好的孩子,天天還挑燈夜讀,對Spring越來越欣賞了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章