SlideShare una empresa de Scribd logo
1 de 14
Dependency Inversion Principle: Intro 1
DIP: definition DEPEND ON ABSTRACTION
DIP: definition DO NOT DEPEND ON CONCRETE OBJECTS
DIP: definition IT’S CALLED INVERSION OF CONTROL .... .... ....
DIP: definition OR DEPENDENCY INJECTION TOO OUT-SOURCING INDIA EFFECTS 5
DIP: practical rules 6 No class should derive from a concrete class No variable should hold a reference to a concrete class No method should override an implemented method of any of its base class
DIP: Inversion of what ?? 7 before after Injector Consumer also high level component depends on an abstraction high level component depens on low level components (concrete classes) interface new() new() new() concrete classes depend on an abstraction Dep1 Dep2 Dep2 Dep1 Dep2 Dep2
DIP: a diagram 8 Take a look at the class diagram concrete classes depend on an abstraction
DIP: Who 9 This 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) 10 publicinterfaceIInjector     { voidInjectDependency(IDependentdependent);     } publicclassInjector : IInjector     { privateIDependent_dependent;         publicvoidInjectDependency(IDependentdependent)         { _dependent = dependent;          }         publicvoidDoSomething()         { _dependent.DoSomethingInDependent();         }    } With this technique we define and use interfaces Let’s define an interface to perform injection Injector implements the interface
DIP: Interface Injection (Type 1) 11 Get the correnct dependency based on config file Create our main class and inject the dependency the method references the dependency, so behaviour depends on the config file IDependentdependency = 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 property Create our main class and inject the dependency IDependentdependency = 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 dependency Create our main class and passing dependency through constructor IDependentdependency = GetCorrectDependency(); Injectorinjector = newInjector(dependency); injector.DoSomething();
DIP: Links  and conclusions 14 Inversion of Control Containers and the Dependency Injection pattern  Introduction to Dependency Injection by Rich Newman  Images from Wacky.com

Más contenido relacionado

La actualidad más candente

What is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaWhat is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaEdureka!
 
Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility PrincipleEyal Golan
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design PrinciplesAndreas Enbohm
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
Refactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGLuca Minudel
 
Clean architecture
Clean architectureClean architecture
Clean architecture.NET Crowd
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkHùng Nguyễn Huy
 
Spring core module
Spring core moduleSpring core module
Spring core moduleRaj Tomar
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Patternguy_davis
 
Interface segregation principle
Interface segregation principleInterface segregation principle
Interface segregation principlemuhammadali0014
 
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean ArchitectureRoc Boronat
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureBadoo
 

La actualidad más candente (20)

What is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaWhat is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | Edureka
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Dependency injection ppt
Dependency injection pptDependency injection ppt
Dependency injection ppt
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility Principle
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Refactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENG
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring core module
Spring core moduleSpring core module
Spring core module
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Interface segregation principle
Interface segregation principleInterface segregation principle
Interface segregation principle
 
Java reflection
Java reflectionJava reflection
Java reflection
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Introducing Clean Architecture
Introducing Clean ArchitectureIntroducing Clean Architecture
Introducing Clean Architecture
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 

Destacado

Open Close Principle
Open Close PrincipleOpen Close Principle
Open Close PrincipleThaichor Seng
 
Solid principles
Solid principlesSolid principles
Solid principlesViet Vu
 
Implementing The Open/Closed Principle
Implementing The Open/Closed PrincipleImplementing The Open/Closed Principle
Implementing The Open/Closed PrincipleSam Hennessy
 
Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principlesrainynovember12
 
Inversion of control
Inversion of controlInversion of control
Inversion of controlEmmet Irish
 
Open Closed Principle kata
Open Closed Principle kataOpen Closed Principle kata
Open Closed Principle kataPaul Blundell
 

Destacado (11)

SOLID Principles part 1
SOLID Principles part 1SOLID Principles part 1
SOLID Principles part 1
 
Open Close Principle
Open Close PrincipleOpen Close Principle
Open Close Principle
 
Solid principles
Solid principlesSolid principles
Solid principles
 
jeas_0816_4883
jeas_0816_4883jeas_0816_4883
jeas_0816_4883
 
Inversion of control
Inversion of controlInversion of control
Inversion of control
 
JavaTalks: OOD principles
JavaTalks: OOD principlesJavaTalks: OOD principles
JavaTalks: OOD principles
 
Implementing The Open/Closed Principle
Implementing The Open/Closed PrincipleImplementing The Open/Closed Principle
Implementing The Open/Closed Principle
 
JavaTalks.Patterns.Singleton
JavaTalks.Patterns.SingletonJavaTalks.Patterns.Singleton
JavaTalks.Patterns.Singleton
 
Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principles
 
Inversion of control
Inversion of controlInversion of control
Inversion of control
 
Open Closed Principle kata
Open Closed Principle kataOpen Closed Principle kata
Open Closed Principle kata
 

Similar a Dependency Inversion Principle

20080531 Intro To Dependency Injection & Inversion Of Control
20080531 Intro To Dependency Injection & Inversion Of Control20080531 Intro To Dependency Injection & Inversion Of Control
20080531 Intro To Dependency Injection & Inversion Of Controldonnfelker
 
Dependency Injection in .NET
Dependency Injection in .NETDependency Injection in .NET
Dependency Injection in .NETssusere19c741
 
Android Dagger 2
Android  Dagger 2Android  Dagger 2
Android Dagger 2Sanket Shah
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, MockingTest Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, Mockingmrjawright
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOSPablo Villar
 
Design for testability as a way to good coding (SOLID and IoC)
Design for testability as a way to good coding (SOLID and IoC)Design for testability as a way to good coding (SOLID and IoC)
Design for testability as a way to good coding (SOLID and IoC)Simone Chiaretta
 
Poco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignPoco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignJames Phillips
 
Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)Dave Hulbert
 
TINTIN: demo of the tool
TINTIN: demo of the toolTINTIN: demo of the tool
TINTIN: demo of the toolErnest Teniente
 
Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)Mohamed Saleh
 

Similar a Dependency Inversion Principle (20)

20080531 Intro To Dependency Injection & Inversion Of Control
20080531 Intro To Dependency Injection & Inversion Of Control20080531 Intro To Dependency Injection & Inversion Of Control
20080531 Intro To Dependency Injection & Inversion Of Control
 
Dependency Injection in .NET
Dependency Injection in .NETDependency Injection in .NET
Dependency Injection in .NET
 
Android Dagger 2
Android  Dagger 2Android  Dagger 2
Android Dagger 2
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, MockingTest Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, Mocking
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
Inversion Of Control: Spring.Net Overview
Inversion Of Control: Spring.Net OverviewInversion Of Control: Spring.Net Overview
Inversion Of Control: Spring.Net Overview
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
 
Design for testability as a way to good coding (SOLID and IoC)
Design for testability as a way to good coding (SOLID and IoC)Design for testability as a way to good coding (SOLID and IoC)
Design for testability as a way to good coding (SOLID and IoC)
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Poco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class DesignPoco Es Mucho: WCF, EF, and Class Design
Poco Es Mucho: WCF, EF, and Class Design
 
Lab (1) installation of python
Lab (1) installation of pythonLab (1) installation of python
Lab (1) installation of python
 
Spring boot
Spring bootSpring boot
Spring boot
 
Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)Silex and Twig (PHP Dorset talk)
Silex and Twig (PHP Dorset talk)
 
TINTIN: demo of the tool
TINTIN: demo of the toolTINTIN: demo of the tool
TINTIN: demo of the tool
 
delphi-interfaces.pdf
delphi-interfaces.pdfdelphi-interfaces.pdf
delphi-interfaces.pdf
 
delphi-interfaces.pdf
delphi-interfaces.pdfdelphi-interfaces.pdf
delphi-interfaces.pdf
 
delphi-interfaces.pdf
delphi-interfaces.pdfdelphi-interfaces.pdf
delphi-interfaces.pdf
 
Dependency injection
Dependency injectionDependency injection
Dependency injection
 
Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)
 

Último

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Último (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Dependency Inversion Principle

  • 2. DIP: definition DEPEND ON ABSTRACTION
  • 3. DIP: definition DO NOT DEPEND ON CONCRETE OBJECTS
  • 4. DIP: definition IT’S CALLED INVERSION OF CONTROL .... .... ....
  • 5. DIP: definition OR DEPENDENCY INJECTION TOO OUT-SOURCING INDIA EFFECTS 5
  • 6. DIP: practical rules 6 No class should derive from a concrete class No variable should hold a reference to a concrete class No method should override an implemented method of any of its base class
  • 7. DIP: Inversion of what ?? 7 before after Injector Consumer also high level component depends on an abstraction high level component depens on low level components (concrete classes) interface new() new() new() concrete classes depend on an abstraction Dep1 Dep2 Dep2 Dep1 Dep2 Dep2
  • 8. DIP: a diagram 8 Take a look at the class diagram concrete classes depend on an abstraction
  • 9. DIP: Who 9 This 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) 10 publicinterfaceIInjector { voidInjectDependency(IDependentdependent); } publicclassInjector : IInjector { privateIDependent_dependent; publicvoidInjectDependency(IDependentdependent) { _dependent = dependent; } publicvoidDoSomething() { _dependent.DoSomethingInDependent(); } } With this technique we define and use interfaces Let’s define an interface to perform injection Injector implements the interface
  • 11. DIP: Interface Injection (Type 1) 11 Get the correnct dependency based on config file Create our main class and inject the dependency the method references the dependency, so behaviour depends on the config file IDependentdependency = 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 property Create our main class and inject the dependency IDependentdependency = 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 dependency Create our main class and passing dependency through constructor IDependentdependency = GetCorrectDependency(); Injectorinjector = newInjector(dependency); injector.DoSomething();
  • 14. DIP: Links and conclusions 14 Inversion of Control Containers and the Dependency Injection pattern Introduction to Dependency Injection by Rich Newman Images from Wacky.com

Notas del editor

  1. Dependency inversion principle