SlideShare a Scribd company logo
1 of 12
Download to read offline
15 minutes IoC
The Constructor Problem

class A {
    private B _b;
    public A() { _b = new B(); }
}
Dependency to the concrete class B

 if B changes the constructor
     A must change as well
 if B becomes new dependencies, e.g. B(C, D), 
     A must create these dependencies as well
 if C, D of B have their own dependencies, e.g. C(E), D
 (F), 
     A must create them too...
A is a 'factory' of Bs

A influences the count created instances of type B
    could be partially solved by the MonoState Pattern
ServiceLocator: temporary solution

    class A {
        private B _b;
        public A(ServiceLocator locator) { 
            _b = locator.get(B.class); 
        }
    }
ServiceLocator problems

 extra dependency to the ServiceLocator
 'push vs pull':we ask for a service, instead of just
 getting the service
 standard API across several libraries: 
    MyServiceLocator vs YourServiceLocator
but A needs *only* the services provided by B,
 ...
e.g. the interface IB
 
 
    class A {
        private IB _b;
        public A(IB b) { _b = b; }
    }
Classes as puzzle pieces

 class A implements IA {
        private IB _b;
        public A(IB b) {
            _b = b; 
        }
    }
 
     in -> required services: IB
     out <- provided services: IA
IoC Container: puzzle table
Flavors

Required services declared/injected on
   field
   setter
   constructor
   method (e.g. init(...))

Wiring
  automatic
  manual: xml, JavaConfig, ...
References
    Gilad Bracha:
        Constructors Considered Harmful 
        Lethal Injection
    Martin Fowler:
        IoC Containers & DI  
    Guice 
    2 min. Pico
     my delicious ioc
 
Pictures:
        http://www.flickr.com/photos/joeyday/147651531/ 
        http://www.flickr.com/photos/jowo/20840165/ 
         http://commons.wikimedia.org/wiki/File:Iceberg_4_1997_08_07.jpg 

More Related Content

Viewers also liked

Further Oral Activity Dear Mama tupac.
Further Oral Activity Dear Mama tupac. Further Oral Activity Dear Mama tupac.
Further Oral Activity Dear Mama tupac. Ahmed Raza
 
Crafting a Tone Thesis
Crafting a Tone ThesisCrafting a Tone Thesis
Crafting a Tone ThesisLisa Huff
 
How to Write a Tone TIQA Paragraph
How to Write a Tone TIQA ParagraphHow to Write a Tone TIQA Paragraph
How to Write a Tone TIQA ParagraphKyla Ward
 
Atmosphereandmood
AtmosphereandmoodAtmosphereandmood
Atmosphereandmoodtcher
 
Further oral activity instructions - assessment
Further oral activity   instructions - assessmentFurther oral activity   instructions - assessment
Further oral activity instructions - assessmenttonia dionysopoulou
 
Writing strong commentary
Writing strong commentaryWriting strong commentary
Writing strong commentaryLisa Huff
 
How to write a good english exam answer
How to write a good english exam answerHow to write a good english exam answer
How to write a good english exam answerGuerillateacher
 
Ib english a language and literature introduction
Ib english a language and literature introductionIb english a language and literature introduction
Ib english a language and literature introductionUtkrisht Pahwa
 
IB Language and Literature outline 2015
IB Language and Literature outline 2015IB Language and Literature outline 2015
IB Language and Literature outline 2015veracaruz
 
Tone Analysis: "A Dream Within a Dream"
Tone Analysis: "A Dream Within a Dream"Tone Analysis: "A Dream Within a Dream"
Tone Analysis: "A Dream Within a Dream"Lisa Huff
 
Literary devices introduction to theme mood and tone
Literary devices introduction to theme mood and toneLiterary devices introduction to theme mood and tone
Literary devices introduction to theme mood and toneGuerillateacher
 
Identifying author's tone
Identifying author's toneIdentifying author's tone
Identifying author's toneBích Phương
 
Language and literature
Language and literatureLanguage and literature
Language and literatureSivabala Naidu
 
Modest proposal sample presentation
Modest proposal sample presentationModest proposal sample presentation
Modest proposal sample presentationReina Shay Broussard
 
Voice and Tone: Creating content for humans (Kate Kiefer Lee)
Voice and Tone: Creating content for humans (Kate Kiefer Lee)Voice and Tone: Creating content for humans (Kate Kiefer Lee)
Voice and Tone: Creating content for humans (Kate Kiefer Lee)Kate Kiefer Lee
 

Viewers also liked (20)

Soaps-tone
Soaps-toneSoaps-tone
Soaps-tone
 
Further Oral Activity Dear Mama tupac.
Further Oral Activity Dear Mama tupac. Further Oral Activity Dear Mama tupac.
Further Oral Activity Dear Mama tupac.
 
Crafting a Tone Thesis
Crafting a Tone ThesisCrafting a Tone Thesis
Crafting a Tone Thesis
 
Ll critical study part 4
Ll critical study   part 4Ll critical study   part 4
Ll critical study part 4
 
How to Write a Tone TIQA Paragraph
How to Write a Tone TIQA ParagraphHow to Write a Tone TIQA Paragraph
How to Write a Tone TIQA Paragraph
 
Atmosphereandmood
AtmosphereandmoodAtmosphereandmood
Atmosphereandmood
 
Further oral activity instructions - assessment
Further oral activity   instructions - assessmentFurther oral activity   instructions - assessment
Further oral activity instructions - assessment
 
SOAPSTone rev
SOAPSTone revSOAPSTone rev
SOAPSTone rev
 
Writing strong commentary
Writing strong commentaryWriting strong commentary
Writing strong commentary
 
How to write a good english exam answer
How to write a good english exam answerHow to write a good english exam answer
How to write a good english exam answer
 
Ib english a language and literature introduction
Ib english a language and literature introductionIb english a language and literature introduction
Ib english a language and literature introduction
 
IB Language and Literature outline 2015
IB Language and Literature outline 2015IB Language and Literature outline 2015
IB Language and Literature outline 2015
 
Tone Analysis: "A Dream Within a Dream"
Tone Analysis: "A Dream Within a Dream"Tone Analysis: "A Dream Within a Dream"
Tone Analysis: "A Dream Within a Dream"
 
Tone lesson-01
Tone lesson-01Tone lesson-01
Tone lesson-01
 
Literary devices introduction to theme mood and tone
Literary devices introduction to theme mood and toneLiterary devices introduction to theme mood and tone
Literary devices introduction to theme mood and tone
 
Identifying author's tone
Identifying author's toneIdentifying author's tone
Identifying author's tone
 
Language and literature
Language and literatureLanguage and literature
Language and literature
 
Modest proposal sample presentation
Modest proposal sample presentationModest proposal sample presentation
Modest proposal sample presentation
 
Voice and Tone: Creating content for humans (Kate Kiefer Lee)
Voice and Tone: Creating content for humans (Kate Kiefer Lee)Voice and Tone: Creating content for humans (Kate Kiefer Lee)
Voice and Tone: Creating content for humans (Kate Kiefer Lee)
 
Author's Tone
Author's ToneAuthor's Tone
Author's Tone
 

Recently uploaded

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

15 Min IoC

  • 2. The Constructor Problem class A {     private B _b;     public A() { _b = new B(); } }
  • 3. Dependency to the concrete class B if B changes the constructor A must change as well if B becomes new dependencies, e.g. B(C, D),  A must create these dependencies as well if C, D of B have their own dependencies, e.g. C(E), D (F),  A must create them too...
  • 4.
  • 5. A is a 'factory' of Bs A influences the count created instances of type B  could be partially solved by the MonoState Pattern
  • 6. ServiceLocator: temporary solution     class A {         private B _b;         public A(ServiceLocator locator) {              _b = locator.get(B.class);          }     }
  • 7. ServiceLocator problems extra dependency to the ServiceLocator 'push vs pull':we ask for a service, instead of just getting the service standard API across several libraries:  MyServiceLocator vs YourServiceLocator
  • 8. but A needs *only* the services provided by B,  ... e.g. the interface IB         class A {         private IB _b;         public A(IB b) { _b = b; }     }
  • 9. Classes as puzzle pieces  class A implements IA {         private IB _b;         public A(IB b) {             _b = b;          }     }   in -> required services: IB out <- provided services: IA
  • 11. Flavors Required services declared/injected on field setter constructor method (e.g. init(...)) Wiring automatic manual: xml, JavaConfig, ...
  • 12. References Gilad Bracha: Constructors Considered Harmful  Lethal Injection Martin Fowler: IoC Containers & DI   Guice  2 min. Pico  my delicious ioc   Pictures: http://www.flickr.com/photos/joeyday/147651531/  http://www.flickr.com/photos/jowo/20840165/   http://commons.wikimedia.org/wiki/File:Iceberg_4_1997_08_07.jpg