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

Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/siemaillard
 
Poster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfPoster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfAlexander Litvinenko
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Celine George
 
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomImplanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomSean M. Fox
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...Nguyen Thanh Tu Collection
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxheathfieldcps1
 
Benefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptxBenefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptxsbabel
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45MysoreMuleSoftMeetup
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...Nguyen Thanh Tu Collection
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...Sumit Tiwari
 
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIII BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIagpharmacy11
 

Recently uploaded (20)

Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
Poster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfPoster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdf
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomImplanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
Benefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptxBenefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
 
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING IIII BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
II BIOSENSOR PRINCIPLE APPLICATIONS AND WORKING II
 

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