Newby Coder header banner

Dependency

What is a dependency in computer science

Dependency is a state in which one component uses a function of another component, and is thus dependent on it

In such cases, the dependant component might require changes when the component used by it is changed

Such components can be a function, class, interface, field

If such components reside in a module of another package, then package of the component using it can be said to be dependant on the other package

The term dependency is often used to refer to package dependency

Direct and Indirect Dependencies

A dependency can be either direct or indirect dependency

If a class A uses a class B then A has a direct dependency on B

If A depends on B, and B depends on C, then A has an indirect dependency on C

Indirect dependencies are also called chained dependencies, or "transitive dependencies"

Similarly, packages can also be directly or indirectly dependent on other packages

What are package dependencies

A package is dependent on another package, if it uses one or more modules of that package

Apart from the modules provided by a programming language, a program might be required to do various other stuff

Programmers can decide to use other packages to implement required functionality instead of writing own code for every functionality related to the core functionality

There can be common packages, for a programming language, which are restricted to a specific use-case and are made available for public use

Some examples are: packages for handling Json or Xml files and data, packages for networking etc

Such packages can be often preferred because of them being maintained, and of the range of functionalities they can provide

This can allow a programmer to focus more on business logic of the program


Software Package dependency in Linux

Similarly, a Linux program can be dependent on some packages or libraries

When such a program is installed, its dependencies must be installed at the same time (if not already)

A user is often prompted to allow installation of these dependent packages when installing a program

By specifying dependencies, packages can be made smaller and simpler, and duplicates of files and programs can be removed