Law of Demeter in MVC regarding Controller-View communication
- by Antonio MG
The scenario: Having a Controller that controls a view composed of complex subviews.
Each one of those subviews is a separated class in a separate file. For example, one of those subviews is called ButtonsView, and has a bunch of buttons.
The Controller has to access those buttons.
Would accessing those buttons like this:
controllerMainView.buttonsView.firstButton.state();
be a violation of the LOD?
On one hand, it could be yes because the controller is accessing the inner hierarchy of the view. On the other, a Controller should be aware of what happens inside the view and how is composed.
Any thoughts?