Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
2  
can you give a more specific idea of how they want to use the controller in the view? –  GSto May 24 '11 at 18:51
    
Get your boss to agree with you and have him tell the developers they have to do it –  briddums Apr 2 '12 at 17:32

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
4  
The last sentence is gold. –  Tamás Szelei May 24 '11 at 19:52
2  
"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 McNabb Aug 8 '11 at 7:40

I tend to use it to restrict the view to only presentation logic.

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.