OOP and MVC

1 points by tudorizer ↗ HN
I'm a strong believer in object oriented programming for too many reasons to enumerate here. Same for MVC, but mostly in web apps. Recently I realized that if I try to enforce OOP in an MVC framework, most of the logic moves away from the controller (C) to the model (M), since that is my main object that performs the actions. An alternative is to move this logic to helpers/utils, actions that come to help the models inside the controller, but put outside the model file (mainly because a lot of logic in the model files slows down the dev server restart).<p>I feel that something is not right in trying to mix MVC with too much OOP. Does anyone have other points of view?

3 comments

[ 2.9 ms ] story [ 14.8 ms ] thread
What you're seeing is actually correct. In MVC, the data and logic reside in the Model, with the Controller only handling communication between the other components.

Don't make the mistake of equating the Model with your Data Layer. They're obviously related, but not equivalent.

There are some variations on MVC where the distribution of responsibilities is different.

"some variations on MVC where the distribution of responsibilities is different"

Most don't. I'm using Django. Recently I've started digging into iOS development (whichs rocks). I know that comparisons between the two are not fair, but I can't help wondering.

As I want to have my code easy to read and maintain, I'm trying to find the best places to put the methods, so they make sense. Any other tips are welcome.

Yes, I should clarify. I don't think any of the MVC-variants encourage business logic to be in the controller. The differences are really in the view and controller layers.

I suppose, strictly speaking, the others -- MVP, MVVM, MVT, etc -- aren't properly called variants of MVC, but they're all aiming for philosophically similar divisions of responsibility.