SlideShare a Scribd company logo
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 Thesis
Lisa Huff
 
Ll critical study part 4
Ll critical study   part 4Ll critical study   part 4
Ll critical study part 4
englishdepartmentmackay
 
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
Kyla Ward
 
Atmosphereandmood
AtmosphereandmoodAtmosphereandmood
Atmosphereandmoodtcher
 
Further oral activity instructions - assessment
Further oral activity   instructions - assessmentFurther oral activity   instructions - assessment
Further oral activity instructions - assessment
tonia dionysopoulou
 
SOAPSTone rev
SOAPSTone revSOAPSTone rev
SOAPSTone rev
Reina Shay Broussard
 
Writing strong commentary
Writing strong commentaryWriting strong commentary
Writing strong commentary
Lisa 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 answer
Guerillateacher
 
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
Utkrisht Pahwa
 
IB Language and Literature outline 2015
IB Language and Literature outline 2015IB Language and Literature outline 2015
IB Language and Literature outline 2015
veracaruz
 
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
 
Tone lesson-01
Tone lesson-01Tone lesson-01
Tone lesson-01
Laura Stickrod Swanson
 
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
Guerillateacher
 
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 literature
Sivabala Naidu
 
Modest proposal sample presentation
Modest proposal sample presentationModest proposal sample presentation
Modest proposal sample presentation
Reina 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
 
Author's Tone
Author's ToneAuthor's Tone
Author's Tone
Sharon Elin
 

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.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
AG2 Design
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
NelTorrente
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.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