Your SlideShare is downloading. ×

15 Min IoC

838

Published on

Short (15min) introduction to IoC principles

Short (15min) introduction to IoC principles

Published in: Education, Technology, Sports
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
838
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 15 minutes 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. A is a 'factory' of Bs A influences the count created instances of type B  could be partially solved by the MonoState Pattern
  • 5. ServiceLocator: temporary solution     class A {         private B _b;         public A(ServiceLocator locator) {              _b = locator.get(B.class);          }     }
  • 6. 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
  • 7. 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; }     }
  • 8. 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
  • 9. IoC Container: puzzle table
  • 10. Flavors Required services declared/injected on field setter constructor method (e.g. init(...)) Wiring automatic manual: xml, JavaConfig, ...
  • 11. 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 

×