SQLManager -取得 SQL 述句( 2/2 ) 例如 得到的 sql 為 select password from UserAccount where id= ‘qing’ String sql = sqlManager.getSQL(“ User.getUserPassword”, “qing”); 自動加上單引號 User.getUserPassword=select password from UserAccount where id= {0}
35.
DBFacade -何謂 Facade Façade 就是建築物正面的入口 The Façade pattern simplifies access to a related sets of objects by providing one object that all objects outside the set use to communicate with the set. *Gamma et al (1995). Design Patterns: Elements of Reusable Object-Oriented Software.
36.
DBFacade -用以實作資料存取的子系統 在應用系統中,總是會找出若干個高度相關的資料表格,對它們所需的存取動作,存在極高的內聚力,我們可以將這些動作聚集在一起,構成一個子系統 例如使用者帳戶管理可能牽扯進幾個表格 User :使用者帳戶資訊 Role :角色 Group :群組 UserRole :使用者所屬的角色 UserGroup :使用者所屬的群組 UserPermission :使用者被賦予的權限 RolePermission :角色被賦予的權限 GroupPermission :群組被賦予的權限 可將對這幾個 table 主要的操作,聚集在一起,成為 UserAccountFacade
DBFacade -更新資料 public int sqlUpdate(String update) 執行 SQL update 述句( insert, delete, update, create table, … ) 回傳更新的資料筆數
48.
如何使用 DBFacade 繼承DBFacade 分析出系統中的子系統,找出每個子系統與底層資料表格的關聯性 設計時基於系統分析的結果( User Case, User Story ),為滿足這些需求,你會為各子系統設計出一個個的 method ( business service ) 針對所設計出來的每個 method ,利用 DBFacade 提供的資料查詢及更新機制予以實作