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