In discussion about my answer to this question, there was some disagreement over how to model this code:
public class MainClass
{
private Something something;
public void Action()
{
OtherClass other = something.GetOtherClass();
}
}
The key points being:
- the
Something
class is an attribute inMainClass
, suggesting an association - the
Something
class is referenced withinMainClass
, suggesting a dependency - A dependency is supposed to be a specialised association
However, since a dependency is can be appropriate in cases where the supplier class is not an attribute, does using a dependency "hide" the intention that the Something
is an attribute, rather than simply referenced?
Furthermore, does an association, which represents an attribute in a class, imply a dependency because it is being stored (and presumably referenced and used in some way).
So, with reference to the above points, does an association imply a dependency, and how would you model the above code in a class diagram?