What're the differences between use and import dependencies?

1.4k Views Asked by At

I'm a bit confused about the differences between use and import dependencies in the package diagrams in UML modelling the java program.

My guess is that when the dependency import is used, the classes in the package being imported are used to instantiate objects in the importing package. When the dependency 'use' is used, the object or attributes or methods in the class of the package being imported are used in the importing package. Whichever dependency I use, I need to write:

public import...

in the code. Is that correct?

2

There are 2 best solutions below

0
qwerty_so On

The difference from a language view is that in the use case you just pick certain parts from a package while the import takes all. Most programming languages take imported packages into their scope so you address elements from the package as being part of the importing itself. For the used ones you usually qualify the namespace.

0
Gerd On

Generally, the use dependency indicates that a model element - not necessarily a package - requires another model element for its implementation (see here and here), whereas the import dependency is more specific to a package and indicates that the importing package's namespace is amended by the imported package (see here).

However, you were asking for the use of both of the dependencies in a package diagram: In this case, I would interpret the use dependency as a looser coupling (e.g. package A just "uses" something from package B). In contrast, the import dependency specifically refers to each element of the imported package with an impact on the namespace.