• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Association and dependency

 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is association a form of dependency relation?
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say the opposite. Association is really the loosest term there is while dependency gives more details, such as the direction of "this particular association."
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are two different concepts in UML:
An association is a channel to send messages object to object. (Well, actually a link - and instance of an association - is the channel.)
A dependency exists between two elements if changes to the definition of one element may cause chagnes to the other. (quoted from UML distilled, 2nd ed.)
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A dependency exists between two elements if changes to the definition of one element may cause chagnes to the other. (quoted from UML distilled, 2nd ed.)


Doesn't that mean that there will be method invocations on the depended object?
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:
Doesn't that mean that there will be method invocations on the depended object?


Not necessarily. It could simply use a declared constant. Or hold a reference to an object without ever calling a method on it, for example.
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
To put it in a nutshell, an association is more persistant than a dependency( so I totally disagree with Lasse's point of view. By the way, a dependencie is definitely not "a particular" association, - dependencie, association and generalization are three different concepts-, and you may also specify a direction with an association: that's called navigation...).
For example, consider the two following simple classes O1 and O2:

Here, every object of type 01 will include a reference to one object of type 02, and these two objects will be closely linked. That's an association (more precisely here, an aggregation).

Now, an exemple of dependency (parameter):


Here, at the end of the execution of method01, link between the two objects will be broken.
Another example of dependency (local object):

Here, when method01 exits, object link02 will die.
So, I would say that an association relationship is stronger than a simple dependency one, in the sense that each object involved is closer to the other one. In the first case, the relation is permanent but not in the second case, where the relation is temporary.
Now, to my sense, there is a more subtil difference to grasp, the one between two forms of association, i.e aggregation and composition.
In both cases, one of the object consitutes a type of attribute for the second one. In our example, link02 of class 02 will be an attribute of object 01. But in the case of composition, the object 02 will born and die with object 01, which is not the case in aggregation relationship. Translated into Java code, it could give somewhat like this:


Both link02 and link03 objects state as attribute for object 01, but in the case of aggregation, link03 object has a somewhat independant life and will not die when 01 will do so.
So if a dependency is not a "particular" association, on the contrary, we may say that composition is a "particular" aggregation.
Hope this helps
Cyril
[ November 30, 2003: Message edited by: cyril vidal ]
[ November 30, 2003: Message edited by: cyril vidal ]
[ November 30, 2003: Message edited by: cyril vidal ]
[ November 30, 2003: Message edited by: cyril vidal ]
[ November 30, 2003: Message edited by: cyril vidal ]
[ November 30, 2003: Message edited by: cyril vidal ]
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by cyril vidal:

Here, every object of type 01 will include a reference to one object of type 02, and these two objects will be closely linked. That's an association (more precisely here, an aggregation).


I don't see how we would know wether the above is an aggregation.


Now, an exemple of dependency (parameter):


In UML 1.x, a parameter could also be modeled as an association (using the parameter stereotype). As far as I know, this changed in UML 2.

Another example of dependency (local object):


Ditto.

So, I would say that an association relationship is stronger than a simple dependency one,


Yes, of course.

But in the case of composition, the object 02 will born and die with object 01


That's not fully true: the composition relationship allows for the whole to give responsibility for a "part" to another "whole".
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hilja,


I don't see how we would know wether the above is an aggregation.


You're right, we don't know whether the above is an aggreagation or a simple association, with no semantic of "whole/part".


In UML 1.x, a parameter could also be modeled as an association (using the parameter stereotype). As far as I know, this changed in UML 2.



Yes. But an association with "local" or "parameter" stereotype specified still remains different from an dependencie with a local or parameter object. In the first case, a type of one object stands as an attribute type for the other one, which is no true in the second case.
Regards,
Cyril.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would think that aggregation and composition are modelling concepts and
how that translates to Java code is something entirely different. I think it's certainly difficult to ascertain the difference b/w an association and aggregation from code (as Ilja pointed out) and whether it's necessary at all.
Fowler blogged on this in May.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by cyril vidal:
Yes. But an association with "local" or "parameter" stereotype specified still remains different from an dependencie with a local or parameter object.


The usage in the community is not very consistent, though.

In the first case, a type of one object stands as an attribute type for the other one, which is no true in the second case.


I am not sure I follow you here. Would you like to elaborate, please? Thanks!
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ilja,


I am not sure I follow you here. Would you like to elaborate, please? Thanks!


Perhaps I'm wrong, but up to now I thought that a association relationship meant a structural relationship, i.e. one object holds permanently the adress of the other one, so includes the type of this object as attrbute type.
For me, that's the great difference with the dependencie, as this last one doesn't require this permanently 'inclusion'. Here, one object is just using another object, most often only during the time of execution of a method. But, when this time elapsed, the first object (dependant) doesn't know anything more about the used one (independant object).
Isn't it the case?
Regards,
[ December 02, 2003: Message edited by: cyril vidal ]
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Not necessarily. It could simply use a declared constant. Or hold a reference to an object without ever calling a method on it, for example.


If it just holds a reference without calling a method why is that called a dependency.
[ December 02, 2003: Message edited by: Pradeep Bhat ]
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I say Aggregation is a subclass of Association?
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:
Can I say Aggregation is a subclass of Association?


Well, neither Aggregation nor Association are classes in any sense I am aware of, I wouldn't say so...
But if you meant to ask wether Aggregation is a special form of Association - yes, that's correct.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:

If it just holds a reference without calling a method why is that called a dependency.


Well, it's at least a compile time dependency.
If A holds a reference to an object of type B, A needs B to be present to be compilable. In fact, most compilers will recompile A every time you change B.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by cyril vidal:
Perhaps I'm wrong, but up to now I thought that a association relationship meant a structural relationship, i.e. one object holds permanently the adress of the other one, so includes the type of this object as attrbute type.


I think it's rather more abstract a relationship. For example, an association might also be implemented by simply holding a unique identifier for the object referenced.
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Well, neither Aggregation nor Association are classes in any sense I am aware of, I wouldn't say so...


I meant some sort of conceptual classes and not real one
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it true that association notation is not supported in UML 2.0?
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:
Is it true that association notation is not supported in UML 2.0?


That would be quite surprising to me.
As far as I know, there were some thoughts to drop Aggregation from UML 2.0. But finally it survived.
 
Are we home yet? Wait, did we forget the tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic