6
Most read
7
Most read
10
Most read
Dependency Inversion Principle: Intro1
DIP: definitionDEPEND ON ABSTRACTION
DIP: definitionDO NOT DEPEND ON CONCRETE OBJECTS
DIP: definitionIT’S CALLEDINVERSION OF CONTROL............
DIP: definitionOR DEPENDENCYINJECTIONTOOOUT-SOURCING INDIA EFFECTS5
DIP: practical rules6No class should derive from a concrete classNo variable should hold a reference to a concrete classNo method should override an implementedmethod of any of its base class
DIP: Inversion of what ??7beforeafterInjectorConsumeralso high level componentdepends on an abstractionhigh level component depens on low level components (concrete classes)interfacenew()new()new()concrete classes depend on an abstractionDep1Dep2Dep2Dep1Dep2Dep2
DIP: a diagram8Take a look at the class diagramconcrete classes depend on an abstraction
DIP: Who9This guy is not a preacher or a wizard: Martin Fowler (*)He gave us three main styles(**) of dependency injection :Interface Injection Setter Injection Constructor Injection(*) but he is still waiting for a call from hollywood(**) and many other things...
DIP: Interface Injection (Type 1)10publicinterfaceIInjector    {voidInjectDependency(IDependentdependent);    }publicclassInjector : IInjector    {privateIDependent_dependent;        publicvoidInjectDependency(IDependentdependent)        {_dependent = dependent;         }        publicvoidDoSomething()        {_dependent.DoSomethingInDependent();        }   }With this technique we define and use interfacesLet’s define an interface to perform injectionInjector implements the interface
DIP: Interface Injection (Type 1)11Get the correnct dependency based on config fileCreate our main class and inject the dependencythe method references the dependency, so behaviour depends on the config fileIDependentdependency = GetCorrectDependency();Injectorinjector = newInjector();injector.InjectDependency(dependency);injector.DoSomething(); Configuration file:<?xml version="1.0"encoding="utf-8" ?><configuration>  <appSettings>    <add key="ClassName"value="DIP.InterfaceInjection.DependentClass1" />  </appSettings></configuration>
DIP: Setter Injection (Type 2)12    publicclassInjector    {privateIDependent_dependent;publicIDependentDependent        {get { return_dependent; }set { _dependent = value; }        }publicvoidDoSomething()        {Dependent.DoSomethingInDependent();        }    }Client class has a propertyCreate our main class and inject the dependencyIDependentdependency = GetCorrectDependency();Injectorinjector = newInjector();injector.Dependent = dependency;injector.DoSomething();
DIP: Constructor Injection (Type 3)13    publicclassInjector    {privateIDependent_dependent;publicInjector(IDependentdependent)        {_dependent = dependent;        }publicvoidDoSomething()        {_dependent.DoSomethingInDependent();        }          }Client class has nothins else a constructor to inject dependencyCreate our main class and passing dependencythrough constructorIDependentdependency = GetCorrectDependency();Injectorinjector = newInjector(dependency);injector.DoSomething();
DIP: Links  and conclusions14Inversion of Control Containers and the Dependency Injection pattern Introduction to Dependency Injection by Rich Newman Images from Wacky.com

More Related Content

PPTX
Dependency Inversion Principle
PPTX
SOLID principles
PPT
SOLID Design Principles
PPTX
Dip(dependency inversion principle) presentation
PPTX
Single Responsibility Principle
PPTX
Solid principles
PPTX
Decorator Design Pattern
PPTX
Open Closed Principle kata
Dependency Inversion Principle
SOLID principles
SOLID Design Principles
Dip(dependency inversion principle) presentation
Single Responsibility Principle
Solid principles
Decorator Design Pattern
Open Closed Principle kata

What's hot (20)

PDF
SOLID Design Principles applied in Java
PPTX
Solid Principles
PDF
Dependency Injection in iOS
PDF
Object Oriented Design Principles
PPTX
Learning solid principles using c#
KEY
SOLID Design Principles
PDF
Introduction to SOLID Principles
PPTX
Solid principles
PDF
Liscov substitution principle
PPTX
Code smell overview
PDF
Clean architecture - Protecting the Domain
PPTX
Clean code: SOLID
PPTX
Domain Driven Design
PDF
Code Smells and Its type (With Example)
PDF
Introducing Clean Architecture
KEY
Solid principles
PDF
Hexagonal architecture - message-oriented software design
PPTX
Hexagonal architecture with Spring Boot
PDF
Domain Driven Design
PPTX
Code smells and remedies
SOLID Design Principles applied in Java
Solid Principles
Dependency Injection in iOS
Object Oriented Design Principles
Learning solid principles using c#
SOLID Design Principles
Introduction to SOLID Principles
Solid principles
Liscov substitution principle
Code smell overview
Clean architecture - Protecting the Domain
Clean code: SOLID
Domain Driven Design
Code Smells and Its type (With Example)
Introducing Clean Architecture
Solid principles
Hexagonal architecture - message-oriented software design
Hexagonal architecture with Spring Boot
Domain Driven Design
Code smells and remedies
Ad

Viewers also liked (10)

PPTX
SOLID Principles part 1
ODP
Open Close Principle
PPTX
Solid principles
PDF
jeas_0816_4883
PPT
Inversion of control
PPT
JavaTalks: OOD principles
PPTX
Implementing The Open/Closed Principle
PPT
JavaTalks.Patterns.Singleton
PPTX
Object Oriented Design SOLID Principles
PPTX
Inversion of control
SOLID Principles part 1
Open Close Principle
Solid principles
jeas_0816_4883
Inversion of control
JavaTalks: OOD principles
Implementing The Open/Closed Principle
JavaTalks.Patterns.Singleton
Object Oriented Design SOLID Principles
Inversion of control
Ad

Similar to Dependency Inversion Principle (20)

PPT
Dependency injection
PDF
Dependency Injection
PPTX
Dependency Injection in .NET
PPTX
How to implement dependency injection in c#
PPTX
Clean Code Part II - Dependency Injection at SoCal Code Camp
PDF
What is Dependency Injection in Spring Boot | Edureka
PDF
Dependency injection for beginners
PPT
20080531 Intro To Dependency Injection & Inversion Of Control
PPT
Dependency Injection & IoC
PPTX
Oleksandr Valetskyy - DI vs. IoC
PPTX
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
DOCX
Dependency Injection
PPTX
Introduction to Dependency Injection
PPTX
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
PPTX
Dependency Injection
PPTX
Clean Code II - Dependency Injection
PPTX
Dependency Injection in Java Essential for Building Maintainable Projects in ...
PPTX
Dependency Inversion
PPTX
Dependency injection using Google guice
PPTX
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Dependency injection
Dependency Injection
Dependency Injection in .NET
How to implement dependency injection in c#
Clean Code Part II - Dependency Injection at SoCal Code Camp
What is Dependency Injection in Spring Boot | Edureka
Dependency injection for beginners
20080531 Intro To Dependency Injection & Inversion Of Control
Dependency Injection & IoC
Oleksandr Valetskyy - DI vs. IoC
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Dependency Injection
Introduction to Dependency Injection
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Dependency Injection
Clean Code II - Dependency Injection
Dependency Injection in Java Essential for Building Maintainable Projects in ...
Dependency Inversion
Dependency injection using Google guice
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp

Recently uploaded (20)

PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PPTX
Internet of Everything -Basic concepts details
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
Auditboard EB SOX Playbook 2023 edition.
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
Advancing precision in air quality forecasting through machine learning integ...
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PDF
Statistics on Ai - sourced from AIPRM.pdf
PDF
Data Virtualization in Action: Scaling APIs and Apps with FME
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PPTX
Microsoft User Copilot Training Slide Deck
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
giants, standing on the shoulders of - by Daniel Stenberg
Early detection and classification of bone marrow changes in lumbar vertebrae...
Internet of Everything -Basic concepts details
Co-training pseudo-labeling for text classification with support vector machi...
Convolutional neural network based encoder-decoder for efficient real-time ob...
Auditboard EB SOX Playbook 2023 edition.
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
Enhancing plagiarism detection using data pre-processing and machine learning...
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
Advancing precision in air quality forecasting through machine learning integ...
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
Statistics on Ai - sourced from AIPRM.pdf
Data Virtualization in Action: Scaling APIs and Apps with FME
The influence of sentiment analysis in enhancing early warning system model f...
Rapid Prototyping: A lecture on prototyping techniques for interface design
Microsoft User Copilot Training Slide Deck
AI-driven Assurance Across Your End-to-end Network With ThousandEyes

Dependency Inversion Principle

  • 3. DIP: definitionDO NOT DEPEND ON CONCRETE OBJECTS
  • 6. DIP: practical rules6No class should derive from a concrete classNo variable should hold a reference to a concrete classNo method should override an implementedmethod of any of its base class
  • 7. DIP: Inversion of what ??7beforeafterInjectorConsumeralso high level componentdepends on an abstractionhigh level component depens on low level components (concrete classes)interfacenew()new()new()concrete classes depend on an abstractionDep1Dep2Dep2Dep1Dep2Dep2
  • 8. DIP: a diagram8Take a look at the class diagramconcrete classes depend on an abstraction
  • 9. DIP: Who9This guy is not a preacher or a wizard: Martin Fowler (*)He gave us three main styles(**) of dependency injection :Interface Injection Setter Injection Constructor Injection(*) but he is still waiting for a call from hollywood(**) and many other things...
  • 10. DIP: Interface Injection (Type 1)10publicinterfaceIInjector {voidInjectDependency(IDependentdependent); }publicclassInjector : IInjector {privateIDependent_dependent; publicvoidInjectDependency(IDependentdependent) {_dependent = dependent; } publicvoidDoSomething() {_dependent.DoSomethingInDependent(); } }With this technique we define and use interfacesLet’s define an interface to perform injectionInjector implements the interface
  • 11. DIP: Interface Injection (Type 1)11Get the correnct dependency based on config fileCreate our main class and inject the dependencythe method references the dependency, so behaviour depends on the config fileIDependentdependency = GetCorrectDependency();Injectorinjector = newInjector();injector.InjectDependency(dependency);injector.DoSomething(); Configuration file:<?xml version="1.0"encoding="utf-8" ?><configuration> <appSettings> <add key="ClassName"value="DIP.InterfaceInjection.DependentClass1" /> </appSettings></configuration>
  • 12. DIP: Setter Injection (Type 2)12 publicclassInjector {privateIDependent_dependent;publicIDependentDependent {get { return_dependent; }set { _dependent = value; } }publicvoidDoSomething() {Dependent.DoSomethingInDependent(); } }Client class has a propertyCreate our main class and inject the dependencyIDependentdependency = GetCorrectDependency();Injectorinjector = newInjector();injector.Dependent = dependency;injector.DoSomething();
  • 13. DIP: Constructor Injection (Type 3)13 publicclassInjector {privateIDependent_dependent;publicInjector(IDependentdependent) {_dependent = dependent; }publicvoidDoSomething() {_dependent.DoSomethingInDependent(); } }Client class has nothins else a constructor to inject dependencyCreate our main class and passing dependencythrough constructorIDependentdependency = GetCorrectDependency();Injectorinjector = newInjector(dependency);injector.DoSomething();
  • 14. DIP: Links and conclusions14Inversion of Control Containers and the Dependency Injection pattern Introduction to Dependency Injection by Rich Newman Images from Wacky.com

Editor's Notes

  • #2: Dependency inversion principle