Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
which design pattern do you implement in order to improve unit testing in your code by loosely coupling object dependencies through object constructor arguments?
1-adapter
2-Dependency Injection
3-Abstract Factory
4-Observer
5-Singleton

What I have tried:

which design pattern do you implement in order to improve unit testing in your code by loosely coupling object dependencies through object constructor arguments?
1-adapter
2-Dependency Injection
3-Abstract Factory
4-Observer
5-Singleton
Posted
Updated 29-May-17 20:52pm

1 solution

Answer:Dependency Injection



Dependency Injection (DI), also more cryptically known as "Inversion of Control" (IoC), can be used as a technique for encouraging this loose coupling. There are two primary approaches to implementing DI: constructor injection and setter injection. Obviously, at some point, something must be responsible for creating the concrete objects that will be injected into another object. The injector can be a parent object, which I'll call the "DI controller", or can be externalized and handled by a "DI container" framework.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900