UML Dependency and Martin Fowler’s Data Mapper Diagram

uml

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?

Best Answer

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.

Related Topic