2011-01-11 44 views
0

嘿傢伙。 我正在閱讀Martin Fowler的PoEA。數據映射模式正在與域對象以這種方式:數據映射器應該引用域模型嗎?

class AbstractMapper... 

    protected DomainObject load(ResultSet rs) throws SQLException { 
     Long id = new Long(rs.getLong(1)); 
     if (loadedMap.containsKey(id)) return (DomainObject) loadedMap.get(id); 
     DomainObject result = doLoad(id, rs); 
     loadedMap.put(id, result); 
     return result; 
    } 
    abstract protected DomainObject doLoad(Long id, ResultSet rs) throws SQLException; 

class PersonMapper... 

    protected DomainObject doLoad(Long id, ResultSet rs) throws SQLException { 
     String lastNameArg = rs.getString(2); 
     String firstNameArg = rs.getString(3); 
     int numDependentsArg = rs.getInt(4); 
     return new Person(id, lastNameArg, firstNameArg, numDependentsArg); 
    } 

這意味着,數據映射是DAL引用域。我認爲DAL不能有這樣的參考。你怎麼看?

回答

2

任何層,包括表示層或數據訪問層,都可以引用域模型。但是,域模型不應該引用這些層,因此可能會重新使用它來支持替代接口和持久性策略。

+0

謝謝你的回答,只是一會兒。如果域不引用DAL,那麼它將如何使用它?也許不需要直接引用DAL,但它需要有一些接口來處理數據源。 – Danil 2011-01-11 15:02:22

相關問題