ViewController:
// ...
myMethod: function () {
this.getView().lookup('myhappyfield').setValue(100);
}
//...
View:
//...
items: [
{
xtype: 'textfield',
reference: 'myhappyfield'
}
]
//...
ViewController:
// ...
myMethod: function () {
this.getView().setHappiness(100);
}
//...
View:
//...
items: [
{
xtype: 'textfield',
reference: 'myhappyfield'
}
],
setHappiness: function (happiness) {
this.lookup('myhappyfield').setValue(happiness);
}
//...
In this example, the two snippets of code perform the same task. However, in the event the reference to myhappyfield
changes or the methodology of indicating 'happiness' changes significantly, the former approach requires changes each place the reference is used.
With separated concerns (the latter example), the view provides an abstracted way to modify 'happiness' that other classes may use. The querying and component manipulation are kept in one place (right alongside the view definition itself!) and the calls to the abstracted method need not change.
Although it is possible for a controller to allow querying down through the layers of a view, it is strongly advisable to abstract that behavior into methods on the view. In this way, a view can provide standardized ways for other classes to influence it and minimize or eliminate changes to other classes when the structure of a view changes.