Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to understand the DataMapper pattern by implementing it myself for one of my domain objects.

So far, I have:

class MyDomainObject
  <business logic methods>

class MyDomainObjectMapper

Now, I need get many MyDomainObjects. These could possibly be held cached in memory (saving many calls to the database). There could also be filter conditions.

Where does this functionality go, according to the pattern? I'm not sure if I should add methods to MyDomainObjectMapper or create a new class.

share|improve this question

That's what an Identity Map is for.

Ensures that each object gets loaded only once by keeping every loaded object in a map. Looks up objects using the map when referring to them.

For a full description see P of EAA page 195

...An Identity Map keeps a record of all objects that have been read from the database in a single business transaction. Whenever you want an object, you check the Identity Map first to see if you already have it.

share|improve this answer
Interesting, I've never heard of that before. Can you explain more about which class is responsible for managing the map? (or maybe it's its own class?) – user39685 Apr 4 '12 at 14:00
Look at Your mapper would use the identity map. – EricSchaefer Apr 4 '12 at 14:24
The Map is a class of its own. – EricSchaefer Apr 4 '12 at 14:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.