Jump to content

Acyclic dependencies principle

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by InternetArchiveBot (talk | contribs) at 10:25, 1 August 2023 (Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.5). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

The acyclic dependencies principle (ADP) is a software design principle defined by Robert C. Martin that states that "the dependency graph of packages or components should have no cycles".[1] This implies that the dependencies form a directed acyclic graph.

Example

[edit]
Circular dependency example

In this UML package diagram, package A depends on packages B and C. Package B in turn depends on package D, which depends on package C, which in turn depends on package B. The latter three dependencies create a cycle, which must be broken in order to adhere to the acyclic dependencies principle.[2]

Types of dependencies

[edit]

Software dependencies can either be explicit or implicit. Examples of explicit dependencies includes:

  • Include statements, such as #include in C/C++, using in C# and import in Java.
  • Dependencies stated in the build system (e.g. dependency tags in Maven configuration).

Examples of implicit dependencies includes:[3]

In general, it's considered good practice to prefer explicit dependencies whenever possible. This is because explicit dependencies are easier to map and analyze than implicit dependencies.

Cycle breaking strategies

[edit]

It is in general always possible to break a cyclic dependency chain. The two most common strategies are:[1]

See also

[edit]

References

[edit]
  1. ^ a b "Granularity: The Acyclic Dependencies Principle (ADP)" (PDF). Object Mentor. Archived from the original on 2015-11-30. Retrieved 2022-11-15.{{cite web}}: CS1 maint: bot: original URL status unknown (link)
  2. ^ Fowler, Martin (2004). UML Distilled.
  3. ^ "Implicit Dependencies Are also Dependencies". O'Reilly. Archived from the original on 2013-05-25. Retrieved 2013-06-16.