Interviews1 answer
Suppose if we have two classes: class A and Class B. How will you make it tightly coupled and then what you should do to make it decoupled.
Posted Oct 13, 2016, 6:40 PM EDT.NET
1 Answer
Tight Coupled Code:
public class A
{
}
public class B
{
private A _a;
public A()
{
_a = new A();
}
}
In the above code, B class has dependency on A class.
Decoupled Code:
Program to Interface is the best way to decouple the code. I will take and Interface and use Dependency Injection specially Constructor Injection.
Posted Oct 13, 2016, 6:40 PM EDT
