Talk:Association versus Dependency
As long as Design by contract is followed, does the difference really matter? This page needs more examples. --MartinvanZijl 03:58, 20 August 2010 (UTC)
I'm kind of confused with this issue, actually. Does anybody have a clear explanation on when we should use a dependency and when should use an association? Right now I tend to use a dependency only when a change in one class would affect another. If two classes only knows about each other like one calls another then I use an association. But I'm only following my hunches, does anyone knows a more decisive explanation than the one here? A Google search only contributed more to my confusion: 1 2 --Mujtaba Alshakhouri 12:27, 24 September 2010 (UTC)
I agree Martin, if Design by contract is followed rigidly then dependancies don't really matter. But that is providing you get your contract perfect first time and don't need to revise it. Considering Association vs Dependency, don't they refer to different things? I was under the impression that Associations were a relationship between two classes, either unidirectional or bidirectional, and that as a result one class was dependent on the interface/name of the other. So if you change something about a class then you need to update any class that is dependent on the changed class. --John Hofman
Okay, apparently my understanding was flawed with Dependency vs Association. Got this right after talking with Wal. A dependency is used when a class has some knowledge about another by some means like if one of its methods expects a parameter of that class. An association however is used only when a class actually contains some instance of the other class. So the idea here is that an association implies strong coupling while a dependency implies only a shallow coupling.