Possible Duplicate:
What is dependency injection?
Spring is the framework from where the concept Dependency Injection came to picture.
What is purpose of DI ? How does it benefit ? How is it implemented ?
Possible Duplicate:
What is dependency injection?
Spring is the framework from where the concept Dependency Injection came to picture.
What is purpose of DI ? How does it benefit ? How is it implemented ?
What is the purpose of DI?
The purpose of Dependency Injection is to reduce coupling in your application to make it more flexible and easier to test.
How does it benefit?
Objects don't have hard coded dependencies. If you need to change the implementation of a dependency, all you have to do is Inject a different type of Object.
How does it implemented?
There are various methods of Dependency Injection. Check out the Wikipedia article to see examples of each. Once you understand those, you can start investigating the various Dependency Injection frameworks.
new to declare class B would make test difficult. Thanks very much in advance.A would be difficult because you have no way to specify the behavior of B for your test. Remember, you only want to test your code...not all the code that your code depends upon.Very short,
What is the purpose of DI? With dependency injection, objects don't define their dependencies themselves, the dependencies are injected to them as needed.
How does it benefit ? The objects don't need to know where and how to get their dependencies, which results in loose coupling between objects, which makes them a lot easier to test.
How is it implemented ? Usually a container manages the lifecycle of objects and their dependencies based on a configuration file or annotations.
new to declare class B would make test difficult. Thanks very much in advance.