Danil
Danil

Reputation: 1893

Should Data Mapper reference Domain Model?

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?

Upvotes: 0

Views: 732

Answers (1)

newdayrising
newdayrising

Reputation: 3802

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.

Upvotes: 2

Related Questions