What is the difference between “needs” and “depends on”?

In this dependency injection starter, I noticed that the UML diagram distinguishes between "use" and "depends on."

Since both require some form of reference in a class that “uses” or “depends on”, I wonder: what is the difference between the two?

+6
source share
2 answers

Check out the block commentary on relationship types taken from the IBM Rational Software Architect documentation .

"depends on" means the following:

A dependency relationship indicates which changes to one element of the model (provider or an independent element of the model) can lead to changes in another model element (client or dependent model element). The vendor model element is independent because the customer change does not affect it. The customer model element depends on the supplier because the change in the supplier affects the customer.

"uses" means the following:

A usage relationship is a relationship relationship in which one model element requires another model element (or a set of element models) for its full implementation or operation. A model element that requires another model element is the customer, and a model element whose presence is required by the supplier. Although the use of a relationship indicates ongoing, it also indicates that the relationship between the two models does not always make sense or is present.

As I read, “use” is a less severe “dependency”.

+3
source

"Uses", where one class refers to another class for some of its operations.

“Depends on” means that class A uses another class B in its implementation (for example, as a parameter to a method). In this case, a change in class B may require a change in class A.

Note. I said a class, but it applies equally to interfaces.

There is a good Wikipedia article: http://en.wikipedia.org/wiki/Dependency_%28UML%29

So, for example, you might have a Uses connection between the class driver and the IVehicle interface, which provides a method called Drive (). Changes to the implementation of Drive do not require any changes to the driver, so you say that the driver uses IVehicle.

However, the Driver class has a dependency on the Hand class, since Driver has two properties: Hand LeftHand and Hand RightHand. If the implementation of these changes has changed, one would have to consider whether the driver needs to be updated accordingly.

+1
source

Source: https://habr.com/ru/post/891768/


All Articles