Does a passive look violate the Law of Demeter?

I am trying to figure out how to use passive browsing correctly. It seems to me that all the examples that I look at the Passive look violate the Law of Demeter:

//In the presenter code
myview.mytextfield.text = "whatever";

So what is the best passive view implementation?

+3
source share
3 answers

Firstly, the Demeter Law, like most programming rules, is rather a principle or a directive, and there are cases when the principle is not applied. However, the Law of Demeter does not really apply to the Passive view, because the cause of the law is not a problem in this case.

Demeter's Law tries to prevent a chain of dependencies, for example:

objectA.objectB.objectC.DoSomething();

, objectB objectD , objectA . , , .

  • , , .
  • , . , .
  • , , . , .

, , , :

//from presenter
view.MeaningfulName = "data";

:

//from view
public string MeaninfulName
{
    get
    {
        return someControl.text;
    }
    set
    {
        someControl.text = value;
    }

, .

+4

, , , , , . , , .

, , . ? ? ?

, Observer - , .


, . . , : , , ( ) , ( ) . , , , "" - , . , , . View , .

Observer, , . , Controller .

+1

API . ( View). View .

Therefore, the Presenter does not need to know anything about the submission, and the Law of Demeter is safe.

+1
source

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


All Articles