Hey guys. I'm reading Martin Fowler's PoEA. Data Mapper pattern is working with Domain objects in this way:
class AbstractMapper...
protected DomainObject load(ResultSet rs) throws SQLException {
Long id = new Long(rs.getLong(1));
if (loadedMap.containsKey(id)) return (D开发者_StackOverflow中文版omainObject) 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);
}
It means that Data Mapper that is DAL references Domain. I thought that DAL must not have such references. What do you think?
Any layer, including a presentation layer or a data access layer, can reference the domain model. However, the domain model should not reference those layers so it can potentially be re-used to support alternative interfaces and persistence strategies.
精彩评论