I have a problem convincing my team mates why we shouldn't use (directly reference) the controller in the view when developing components in the spirit of MVC.
I have invoked decoupling and natural intuition, but still those arguments didn't get through.
They say, in their defense, that this is a normal compromise.

What arguments are convincing? Or they are right? How can the practice of using the controller in the view could affect a project on the long run?

2 Answers
2

The View can have an indirect association to the Controller. Is it mandated? No, but it is certainly acceptable. When you state reference; I am assuming you are referring to a direct association between the View and the Controller which is typically avoided since it couples the View to a given Controller.

The idea is the isolation of concerns (maintainability) and the facilitation for better testing across the product. If other practices are being followed, the benefit to this separation should surface immediately; if not it may be the first step in this debate (CI, TDD, etc...).

If this is nothing more then an architecture pissing match; everyone is right and wrong and you all should move forward in the most maintainable way possible.

"which is typically avoided since it couples the View to a given Controller" <-- THIS. Often it makes sense for a view to be used in multiple places. For instance, imagine an order of goods. You may use the same view for the user to review the order, as for the supplier to act on an order. Obviously, the controller which allows a supplier to authorise an order should not be referenced by this view, and neither should the controller from where the order is being placed.
–
Vincent McNabbAug 8 '11 at 7:40

A rule of thumb is that in cases where you find you need to access the concerns of one layer of an MVC app from a different layer, it is usually due to a deficiency in one of the other layers.

If you find yourself needing to access the controller from the view, you might want to look at the model and view and ask if it needs some additional data to track state, handle missing or ambiguous data or forward to an error or exception state.