I'm trying to understand how to use Passive View correctly. It seems to me that every examples I look at on Passive View breaks the Law of Demeter :
//In the presenter code
myview.mytextfield.text = "whatever";
So what's a better implementation of Passive View?
First, the Law of Demeter, like most rules of programming, is more of a principle or guideline and there are occasions when the principle doesn't apply. That being said, the Law of Demeter doesn't really apply to Passive View because the reason for the law isn't a problem in this case.
The Law of Demeter is trying to prevent dependency chaining such as:
objectA.objectB.objectC.DoSomething();
Obviously if objectB's implementation changes to use objectD instead then it will break objectA's dependency and cause a compilation error. If taken to an extreme you wind up doing shotgun surgery any time the chain is disturbed by an implementation change.
In the case of Passive View
So the example you gave would normally be implemented:
//from presenter
view.MeaningfulName = "data";
While the view would be something like:
//from view
public string MeaninfulName
{
get
{
return someControl.text;
}
set
{
someControl.text = value;
}
Hope this clarifies things a bit.