Reputation: 2123
In my project I am using a Domain Driven Design Pattern. I have various data mappers that I use for persisting my model objects. Some of my models contain other models as attributes (e.g., model class Book contains an array of model classes Person as authors).
Book
|->string title
|->Person[] authors
Each model has a corresponding mapper (e.g. Book_Mapper, Perspon_Mapper).
Is it ok for one mapper to make a call to another mapper when persisting a model object:
E.g., when persisting a Book object, I call
Book_Mapper::Save(Book)
which calls
Person::Mapper(Person)
for each author of the book?
Upvotes: 2
Views: 1249
Reputation: 37739
From a DDD perspective, to address the question regarding data mappers it is important to first distill your model a bit and determine your aggregates, entities and value objects.
Suppose that Book
is an aggregate and a Person
is a value object. In that case, there is no need to create a separate mapper for Person
because it is always persisted as part of the Book
aggregate and so the mapper for books should handle mapping the person as well. In fact, creating a separate mapper for person may be confusing.
If however Person
is also an aggregate, then it would be best to have Book
reference the author by ID alone. In this case, there is no need to call the person mapper when persisting a book.
Upvotes: 5