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不能有這樣的參考。你怎麼看?
謝謝你的回答,只是一會兒。如果域不引用DAL,那麼它將如何使用它?也許不需要直接引用DAL,但它需要有一些接口來處理數據源。 – Danil 2011-01-11 15:02:22