Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

So far, I have:

class MyDomainObject
  <attributes>
  <business logic methods>

class MyDomainObjectMapper
  save
  update
  delete
  get

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
add comment

1 Answer

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

http://martinfowler.com/eaaCatalog/idMapperSketch.gif

...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?) –  Matt Fenwick Apr 4 '12 at 14:00
    
Look at martinfowler.com/eaaCatalog/identityMap.html 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
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.