SlideShare a Scribd company logo
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
Dependency injection and inversion
PPT
Structural patterns
PDF
PPTX
Design Pattern - Factory Method Pattern
PPT
SOLID Design Principles
PPTX
React render props
PPT
Docker introduction
Dependency Inversion Principle
Dependency injection and inversion
Structural patterns
Design Pattern - Factory Method Pattern
SOLID Design Principles
React render props
Docker introduction

What's hot (20)

PPTX
SOLID Principles
PPTX
Dip(dependency inversion principle) presentation
PPTX
A Practical Guide to Domain Driven Design: Presentation Slides
PPTX
SOLID principles
PDF
Secret Management with Hashicorp’s Vault
PDF
Solid Principles
PPTX
Object Oriented Programing JAVA presentaion
PPT
Final keyword in java
PDF
Microservices Communication Patterns with gRPC
PDF
Kubernetes architecture
PPTX
Docker basics
PDF
Dependency Injection in iOS
PPT
PPTX
Introduction to docker
PPTX
Angular Data Binding
PDF
A Hands-On Introduction To Docker Containers.pdf
PDF
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
PPTX
Learning solid principles using c#
PDF
Bridge pattern for Dummies
PDF
Introduction to docker
SOLID Principles
Dip(dependency inversion principle) presentation
A Practical Guide to Domain Driven Design: Presentation Slides
SOLID principles
Secret Management with Hashicorp’s Vault
Solid Principles
Object Oriented Programing JAVA presentaion
Final keyword in java
Microservices Communication Patterns with gRPC
Kubernetes architecture
Docker basics
Dependency Injection in iOS
Introduction to docker
Angular Data Binding
A Hands-On Introduction To Docker Containers.pdf
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
Learning solid principles using c#
Bridge pattern for Dummies
Introduction to docker
Ad

Viewers also liked (11)

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
PPTX
Open Closed Principle kata
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
Open Closed Principle kata
Ad

Similar to Dependency Inversion Principle (20)

PPT
20080531 Intro To Dependency Injection & Inversion Of Control
PPTX
Dependency Injection in .NET
PPTX
Android Dagger 2
PPTX
Test Driven Development:Unit Testing, Dependency Injection, Mocking
PPT
Intro To AOP
PPTX
Inversion Of Control: Spring.Net Overview
PPTX
C++ Constructs.pptx
PDF
Spring core module
PPTX
Design for testability as a way to good coding (SOLID and IoC)
PPTX
Dependency Injection
PPTX
Poco Es Mucho: WCF, EF, and Class Design
DOCX
Lab (1) installation of python
PPTX
PDF
Silex and Twig (PHP Dorset talk)
PPTX
TINTIN: demo of the tool
PDF
PDF
PDF
PDF
Dependency injection
PDF
CDS views SAP S4 Hana detail guide .pdf
20080531 Intro To Dependency Injection & Inversion Of Control
Dependency Injection in .NET
Android Dagger 2
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Intro To AOP
Inversion Of Control: Spring.Net Overview
C++ Constructs.pptx
Spring core module
Design for testability as a way to good coding (SOLID and IoC)
Dependency Injection
Poco Es Mucho: WCF, EF, and Class Design
Lab (1) installation of python
Silex and Twig (PHP Dorset talk)
TINTIN: demo of the tool
Dependency injection
CDS views SAP S4 Hana detail guide .pdf

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Modernizing your data center with Dell and AMD
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
Teaching material agriculture food technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
A Presentation on Artificial Intelligence
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
KodekX | Application Modernization Development
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Modernizing your data center with Dell and AMD
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
Teaching material agriculture food technology
Advanced methodologies resolving dimensionality complications for autism neur...
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
A Presentation on Artificial Intelligence
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KodekX | Application Modernization Development
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...

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