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
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
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