views:

87

answers:

1

Hi all Im trying to build a solution using a DDD approach. Ive created a set of entities, and some datamappers i use to remove the data persistence dependency from the entities. Is it correct of me, to use a datamapper like a "finder" class, i have methods like

getById() getUsersByRanking() getByLastName()

or should the datamapper not contain specialized finder methods and only use getById()?

Is it correct of me to assume that the Repository pattern is used to remove those "specialized" finder methods that i have added to the datamapper, and instead give the client a Query Language that they can use instead to find entities by other means than the ID?.

I really hope someone can help me clarify how these patterns interact with each other Domain model, Datamapper, Data presistence, Repository.

Ive read alot in the Martin Fowler POEAA but having a hard time connecting the dots :)

A: 

Lets's sat that respositories are entry point for entities in DDD. you can create abstract one and then specialize it to each entity. So you can ask a repository every time you need to get an entity. The datamapper is a solution to map entities with their database representations or any other storages. So I guess that datamapper has to be hidden behind the repository pattern.

Arseny
As i talked with WeNeedAnswers in the above comments, my problem is that the distinction between when to add the Repository abstraction around my datamapper is very hard to see, many examples i see on the net, looks like they are using datamapper's and repositories interchangely, many people talk about the Repository is adding a Collection like interface to your domain objects, but as i see it thats what the datamapper does aswell.
madsleejensen
@madsleejensen you should not interchange Repository and DM 'cause at least DM is NOT DDD's concept. As WeNeedAnswers wrote "The responsibility of the data-mapper(s) is to bring this data in and map it to your repository objects". So you may consider DM as specific mechanism behind Repository concept.
Arseny