What are hidden addictions?

Can someone please give me an example of hidden addiction. I searched it and found the results as follows:

"A visible dependency is a dependency that developers can see from the class. If the dependency cannot be visible from the class interface, this is a hidden dependency."

(Source - http://tutorials.jenkov.com/ood/understanding-dependencies.html#visiblehidden )

But I still do not quite understand.

Does this mean when the dependency occurs inside the function, and not the declared variable at the beginning of the class? Or is it just when you just create functions other than the signature methods declared in the interface?

+4
source share
1 answer

:

class Foo 
{
    void doSomething() //a visible method signature
    {
        //the body of this method is an implementation detail
        //and is thus hidden
        new Bar().doSomething();
    }
}

Bar Foo, Foo Bar.

, Bar Foo Foo.

, . . doSomething() , , . , , , doSomething(), void.

, :

class Foo 
{
    private readonly Bar bar;

    Foo(Bar bar) //the constructor signature is visible
    {
        this.bar = bar;
    }

    void doSomething() 
    {
        bar.doSomething(); 
    }
}

Bar .

:

class Foo 
{

    void doSomething(Bar bar) //method signature is visible
    {
        bar.doSomething();
    }
}  

Bar doSomething , doSomething.

+7

Source: https://habr.com/ru/post/1687059/


All Articles