Reputation: 1918
Im on a learning curve of domain modeling and mappers. Is it ok to call another mapper inside a model? For example:
class model_project extends model {
[...]
public function addTag($tag)
{
$tagMapper = new Mapper_Tag;
$tag = $tagMapper->findByName($tag);
if(!$tag) {
// create new $tag
$tagMapper->save($tag);
}
}
[...]
}
I mean, is it ok to call some save function on mapper to get some login working on model or is it forbidden by a good pratice?
Upvotes: 1
Views: 111
Reputation: 16358
A domain model shnould not know about other infrastructure like mapper. Teh domain model are simply objects which are modelling the domain. THose objects are created by a Factory or restored by a Repository, both outside the domain.
The domain model shouldn't care about saving or other things which makes no sense in that Bounded Context where it belongs.
Upvotes: 3