Sobes.tech
Junior — Senior

Disadvantages of direct dependency through constructor

livecode

Task condition

Class A receives an object of class B through the constructor and calls its method Bar() inside its own method Foo(). What potential problems can arise from such an organization of code?

public class A(B dependency)
{
    public void Foo()
    {
        ...
        this.dependency.Bar();
        ...
    }
}