Quickstart Guide         

SOLID

Dependency inversion principle

Definition

Dependency inversion principle

High-level modules should not depend on low-level modules.

Both should depend on abstractions (e.g. interfaces).

https://en.wikipedia.org/wiki/Dependency_inversion_principle

Definition

Dependency inversion principle

Abstractions should not depend on details.

Details (concrete implementations) should depend on abstractions.

https://en.wikipedia.org/wiki/Dependency_inversion_principle

High/Low level & boundary

Dependency inversion principle

https://clevercoder.net/2018/09/08/clean-architecture-summary-review/

The inversion

High/Low level & boundary

Dependency inversion principle

https://clevercoder.net/2018/09/08/clean-architecture-summary-review/

If the principle is applied, high-level classes are not affected by any changes to low-level classes.

In addition, high-level classes can be reused in any context that defines lower-level classes that implement an abstract interface defined in upper-level classes.

High/Low level & boundary

Dependency inversion principle

https://clevercoder.net/2018/09/08/clean-architecture-summary-review/

Less stable classes and components should depend on more stable ones, and not the other way around.

Clean Architecture

Dependency inversion principle

Clean Architecture: A Craftsman's Guide to Software Structure and Design

the most flexible systems are those in which ...

Source code dependencies refer only to abstractions, not to concretions.

Clean Architecture

Dependency inversion principle

Clean Architecture: A Craftsman's Guide to Software Structure and Design

more practically ...

Avoid to depend on volatility concrete factors.

The stable abstraction

Dependency inversion principle

Clean Architecture: A Craftsman's Guide to Software Structure and Design

Create Objects by Abstract Factory

#1

Only refer to abstraction interface,

The stable abstraction

Dependency inversion principle

Clean Architecture: A Craftsman's Guide to Software Structure and Design

Don't derive from volatile classes

#2

The stable abstraction

Dependency inversion principle

Clean Architecture: A Craftsman's Guide to Software Structure and Design

Don't override concrete methods

#3

It's bad inheritance.

Explain by Example

Dependency inversion principle

higher module depend on lower module

Explain by Example

Dependency inversion principle

Invert the dependency

Explain by Example

Dependency inversion principle

https://refactoring.guru/design-patterns/abstract-factory

Abstract Factory

Explain by Example

Dependency inversion principle

Further more... we can pass the dependency management to third party / system level.

Dependency inversion pattern generalization

Dependency inversion principle

Ioc - Inversion of Control

To decouple the execution of a task from implementation

“Hollywood Principle: Don’t call us, we’ll call you”.

Separate what-to-do and when-to-do

Dependency inversion pattern generalization

Dependency inversion principle

To decouple the execution of a task from implementation

To focus a module on the task it is designed for.

To free modules from assumptions about how other systems do what they do and instead rely on contracts.

To prevent side effects when replacing a module.

Dependency inversion pattern generalization

Dependency inversion principle

Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.

DI - Dependency Injection

IoC & DI in Framework

Dependency inversion principle

https://docs.nestjs.com/fundamentals/custom-providers

IoC & DI in Framework

Dependency inversion principle

https://docs.nestjs.com/fundamentals/custom-providers

IoC & DI in Framework

Dependency inversion principle

https://docs.nestjs.com/fundamentals/injection-scopes

Dependency inversion principle

IoC & DI in Framework

https://laravel.com/docs/7.x/container

In Infra Service Level

Dependency inversion principle

https://www.youtube.com/watch?v=gfh-VCTwMw8

In Infra Service Level

Dependency inversion principle

https://www.youtube.com/watch?v=gfh-VCTwMw8

In Infra Service Level

Dependency inversion principle

https://www.youtube.com/watch?v=gfh-VCTwMw8

Futher more ... CQRS

Search updating worker can listen on change event from Price service

Recursive Dependency -> SOA

Dependency inversion pattern generalization

Dependency inversion principle

https://en.wikipedia.org/wiki/Dependency_inversion_principle

Dependency inversion principle

By guansunyata

Dependency inversion principle

  • 358