oopdependenciesuml

What is the definition of dependency in UML


In UML, we know there is a term "dependency".

enter image description here

We are eager to know what the definition of dependency is. For example:

class B {}

class A {
  constructor(b: B){...}
}
  1. We know that the instantiation of b is not inside A. In this case, does it mean that A does not depend on B?
  2. Person.ts imports Animal.ts. Then is Person.ts dependent on Animal.ts?

===

There is an relation answer, but I don't think it's a good explanation.


Solution

  • Dependency is the most general relationship between two elements.

    You can think of the dependency relationship like this: A depends on B is changes to B might necessitate changes to A.

    When talking about TypeScript, the first thing that indicates a dependency is the import keyword (note that sometimes there is an implicit import).


    Looking at your cases:

    1. A depends on B because changes in B might necessitate changes to A.
    2. Person.ts depends on Animal.ts because changes in Animal.ts might necessitate changes to Person.ts.

    P.S. For example, if there are association, aggregation, composition, generalization, or realization relationship between A and B, then A depends on B because changes to B might necessitate changes to A.