I'm trying to get a better understanding of Dependency.

In Martin Fowler's explanation of the Data Mapper pattern, http://martinfowler.com/eaaCatalog/dataMapper.html, the UML diagram shows the Mapper being dependent on both the Domain Object and the Database.

It seems to me, however, that the Domain Object is dependent on the Mapper. For example, if the interface of the Mapper changes, the Domain Object may need to change. I would have expected a dependency to be shown from the Domain to the Mapper.

At another level, I can see that the Mapper is dependent on the Domain Objects. Domain Objects, of all classes, are likely to change, and sure, this is likely to cause changes in the Mapper.

I guess I'd feel happier if the Domain/Mapper dependency was bi-directional. Am I missing something? Or do I just need to loosen up a bit? Perhaps Martin only shows the dependency in one direction because it is the overwhelmingly more important direction?

  • Ah, now I see! I was under the impression that the Domain Object would need to be aware of the Mapper, even if just to generate an object. But I see that this is done in the presentation layer...
    – DatsunBing
    Commented May 9, 2012 at 7:02

1 Answer 1


Your domain object and the database should have no idea that a mapper exists. Your mapper is created after the domain and the database has been created. Hence the mapper is dependent on both the database and the object.

If you designed your domain object to have a "notion" that a mapper is in place, It may mean that your domain object is highly coupled with the mapper which should not be the case.

  • +1 for good explanation. Also, you could determine dependency by identifying which objects does the mapper need to know about so it could have a valid instance. In this case, it needs the database and the person. However, you could create a person instance without knowing the mapper exists. See this if you like: uml-diagrams.org/dependency.html
    – NoChance
    Commented May 9, 2012 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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