数据映射器应该引用域模型吗?
嘿伙计们。 我正在读马丁·福勒的《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一定不会有这样的引用。你怎么认为?
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 (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);
}
It means that Data Mapper that is DAL references Domain. I thought that DAL must not have such references. What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
任何层,包括表示层或数据访问层,都可以引用域模型。但是,域模型不应引用这些层,因此它可以被重用以支持替代接口和持久性策略。
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.