顯示具有 persistence layer 標籤的文章。 顯示所有文章
顯示具有 persistence layer 標籤的文章。 顯示所有文章

2017年12月27日 星期三

Java Spring - Spring JDBC

  • Spring data-access
    • Spring的目標之一就是允許在開發的時候,能夠遵循OO原則中的coding to interface。Spring對data的support也是如此
    • 為了避免persistence logic分散到各個component,最好將data access放到一個或多個專注在此任務的component中
    • 這樣的component通常稱為data access object, DAO或repository
    • 為了避免application和特定的data access strategy,良好多repository應該要用interface的方式顯示功能
      • service object ---> repository interface <--- repository implementation
    • service object本身並不會處理data access,而是會將data access delegate給repository,repository interface確保和service object decoupling
      • 好處:service object好測試,因為不需要和特定的data access implementation綁在一起,也可以為這些interface建立mock implementation,無需連接DB就能夠測試service object
      • 只有data access相關的method才透過interface exposed。這可以實現靈活設計,且切換data-persistence framework對應用程式其他部分帶來影響最小。如果將細節滲透到application的其他部分,則整個application將和data access layer couple在一去,導致僵化的設計
    • interface&Spring: 
      • interface是實現low coupling的key,並且應將其應用在application的各個layer