Law of Demeter in MVC regarding Controller-View communication
Posted
by
Antonio MG
on Programmers
See other posts from Programmers
or by Antonio MG
Published on 2013-10-25T13:54:14Z
Indexed on
2013/10/25
16:10 UTC
Read the original article
Hit count: 209
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?
© Programmers or respective owner