difference between unidirectional association and dependency

According to wikipedia

Dependency is a relationship that shows that an element, or set of elements, requires other model elements for their specification or implementation.[1] The element is dependent upon the independent element, called the supplier.

So is it not the same as unidirectional association? Do we use dependency when an operation in one class uses object of the other class as its parameter?

How are unidirectional association and dependency different. Any example would be very helpful

Answers


Association means that the two associated entities are linked semantically. Dependency only declares that there is a... well, dependency of some sort. All associations are dependencies, while a dependency does not actually mean association. For example, class 'A' depends on class 'B' if it has a method that takes 'B' and passes it as argument to a function in another class. But if 'A' calls some method of class 'B', it should be modeled as association.

Disclaimer I have read the UML specification and also asked myself this question a number of times. I arrived at at the definition above, but I'm still not sure it is 100% correct.


Dependency :

Indicates that a client element(of any kind, including classes, packages, use cases, etc) has knowledge of another supplier element, and a change in supplier can effect the client.

So "dependency" is very broad relationship.Suppose that if a class-object(client) has another class-object(supplier) as a member,if a class-object send a message to another class-object,if a class-object takes another class-object as an parameter from its methods, even if a class(client) is subclass of another class(supplier) there will be dependency since change from supplier will effect clients.

Technically all of those relationships can be shown by "Dependency" line. But some of above relationships already has special notations: such as for superclass-subclass relationship we have generalization relationship.No need to show also "dependency" line because if they have generalization relationship, they have dependency. And we have "association" relationship for class-object(client) who has another class-object as a member [attribute]. So also no need to show extra dependency line in this situation.

Actually "Dependency" is badly defined relationship for class diagrams. But it can be usefull for showing dependency in which UML has no special notation such as :

  • if you has another class-object(supplier) as a parameter in one of your class(client) methods
  • if you have dependency to global variables
  • when you call static methods on another classes.
  • local variables (which you think you have important dependency)

public class RepositoryManager
{
     public UpdatePriceFor(ProductDescription description)
     {
          Time date = Clock::GetTime();
          Money oldPrice =description.GetPrice();
          ...
     }

    private  IList<Item> itemsList = new List<Item>();

}

So all "associations" are also shows "dependency".But "dependency" is broad-general-weak relationship.As a rule if there is a special relationship which is more specific-stronger than dependency relationship than use it. And lastly use all your relationship "economically". Show only important ones based on modeler-model reader perspectives.

[ Source : Adapted from Craig Larman's Applying UML and Patterns book ]

Check Fowlers bliki for further information DependencyAndAssociation


Need Your Help

Correcting a Java Program Code Fragment

java java.util.scanner

I am a beginner level of studying java and revising for my exams through answering the questions on previous past exam papers and there is one question that I am stuck on.

How to generate all permutations of a list in Python

python algorithm permutation combinatorics python-2.5

How do you generate all the permutations of a list in Python, independently of the type of elements in that list?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.