Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
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... –  Kim May 9 '12 at 7:02
add comment

1 Answer

up vote 5 down vote accepted

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.

share|improve this answer
    
+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 –  Emmad Kareem May 9 '12 at 6:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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