Skip to content
StackDecode
System Design
15. Software Design PatternsAnimated

Dependency Inversion

Depend on abstractions, not concrete classes.

The idea

High-level modules and low-level modules both depend on interfaces.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

Web adapterTest adapterDomain coreRepo adapterMail adapter
  • client
  • gateway / proxy
  • service
  • cache
  • data store
  • queue / stream

The domain core has no knowledge of web, database or email.

step:
1/4
at:
Domain core
1/7

The green dot is a request moving through the system.

Step by step

  1. 1Define an interface in the high-level module
  2. 2Implement it in the low-level one
  3. 3Inject the implementation
  4. 4Dependencies point to abstractions

Where it is used

Clean architecture.

Watch out for

Do not abstract everything.

Related