Dependency refers to a relationship between two or more software components or modules, where one component relies on another component to perform functions or provide services. In other words, a dependency exists between two elements if changes to one may cause changes to the other.

Various reason for dependency

  • Once class send message to another
  • One class has another as its data
  • One class mention another as a parameter to an operation
  • One class is a superclass or interface of another

Why we have dependency

Code reusability

Dependencies allows developer to reuse existing code and libraries whether internal or external. By developing on well-established libraries or modules, developers can save time and effort without writing new code or rewriting the existing code.

Modularity

Dependencies help in creating modular and maintainable code. Breaking down complex systems into smaller, more manageable components can significantly improve the overall system maintainability, testability, and ease for future extensions.

Types of dependencies

  • Compile time dependencies: compile time dependencies are required during the compilation or build phase of a software project. They are typically external libraries or modules that need to be present for the code to compile successfully.
  • Runtime dependencies: These dependencies are required for the software to execute correctly during runtime. That may include external libraries, database, web services or others.
  • Transitive dependencies: Dependencies can have dependencies of their own. Transitive dependencies are those that are indirectly required by you software.

Dependency management tools

Dependency management helps to manage and handle external libraries, packages and dependencies efficiently. Those tools assist developer in downloading, installing, updating, and resolving dependencies required by their projects.

Maven

Target language: Java Apache Maven is a build automation tool and project management tool for Java projects. One of its features is dependency management, allowing developers to specify project dependencies in a pom.xml file. Maven can fetch and resolve dependencies from central repository. (more on Apache Maven)

Gradle

Target language: Java Gradle is another build automation tool and project management tool, often used as an alternative to Apache Maven. It supports multiple programming languages and provides a flexible dependency management system. (more on Gradle)

Dependency Injection (DI)

DI is a design pattern that allows you to inject dependency into a component rather than having the component to create or manage its dependencies. This promotes loose couplingand makes it easier to change to substitute dependencies. (More on Dependency Injection (DI))


DependencyDIGradleMavenLoose_coupling