3

I have been studying, playing with and working with ASP.NET MVC since Preview 1 in 2007 (december). I have been a fan of it since 2008 and I support it all the way.

However I keep hearing and reading "ASP.NET MVC enforces a strict separation of concerns", including reading it in Professional ASP.NET MVC 1.0 by Rob Conery, Scott Hanselman, Phil Haack and Scott Guthrie.

What I don't understand is the enforcement. What if I define my controller with actions with nothing but

return View();

and in the view (aspx view engine) I do everything? (data fetching, business logic, decision making, rendering etc.)

How does it (ASP.NET MVC) ENFORCE me to separate the concerns?

I think this is a blatant overstatement and it should read "suggests a separation of concerns".

Can you convince me it enforces?

artless noise
  • 21,212
  • 6
  • 68
  • 105
Andrei Rînea
  • 20,288
  • 17
  • 117
  • 166
  • 1
    To the silent downvoter : as the site says... "provider an answer for downvoting" – Andrei Rînea Aug 06 '09 at 19:35
  • 2
    I'm the silent downvoter. My feeling is that this question adds little value to Stack Overflow. It's clear from your example where all the logic is in the ASPX page that "enforcement" is probably not the right term for the documentation to use. So, yes, you are correct. The framework does not enforce a strict separation. But I'm not sure why this is valuable information or why anyone would ever care to look up whether MVC enforces or encourages a separation of concerns. It feels like splitting hairs over something that isn't that important, hence my downvote. – JamieGaines Aug 06 '09 at 19:45
  • word... Of course it doesn't ENFORCE you to have a separation of concerns. Its a guide or a "framework" that you can choose to follow or not. if i had my lame 100 points i would down vote this too. – YetAnotherDeveloper Aug 06 '09 at 19:51
  • I was hoping there is some hidden switch (as in "strict_mode" stuff) somewhere which would ACTUALLY enforce little access in the view or in the controller? Well I guess there isn't it and the answers I got so far seem to point me to this. Thank you for clarifying! :) – Andrei Rînea Aug 06 '09 at 19:51
  • 2
    @thinkzig it's clear for you, what about for one who asked the question? – pageman Aug 06 '09 at 19:52
  • @YetAnotherDeveloper I would vote your stuff just to get you to the threshold that would enable you to downvote my question. But you don't have any questions as I can see in your profile. – Andrei Rînea Aug 06 '09 at 19:53

4 Answers4

7

The primary thing is that it start off on the right foot - i.e. a separate controller and view. If you choose to do something crazy, nobody will stop you. Except hopefully peer reviews. And common sense.

But contrast to webforms, where you have to try very hard not to mix the concerns.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
4

I don't think it enforces it, so they probably mispoke. Like you said, "suggests" or "promotes" is a better word.

rball
  • 6,925
  • 7
  • 49
  • 77
  • Thank you. Well in "Professional ASP.NET MVC 1.0" by 4 of the main guys at Microsoft on page 86, row 27 states "One of the defining characteristics of the MVC pattern is the *strict separation of concerns it helps enforce* between the different components of an application. – Andrei Rînea Aug 06 '09 at 19:40
  • 2
    I think the key there is *helps* enforce. – Matt Grande Aug 06 '09 at 19:42
  • I agree with Matt, you'd have to go out of your way to do something like put a GridView in there. – rball Aug 06 '09 at 19:53
  • 1
    I think the same way that RoR is "opinionated", you could probably think that it gives an "opinion" – pageman Aug 06 '09 at 19:53
2

Sure, you can do everything in the view. You'd just be a terrible programmer, and wouldn't be following the MVC pattern at all.

I'm also pretty sure there are some things you cannot do in the view at all, only in the controller. I may have my .Net and Rails confused, though.

Matt Grande
  • 11,964
  • 6
  • 62
  • 89
2

What mechanism would you suggest for "enforcement" of the kind you want? Should the framework issue warnings when the cyclomatic complexity of View code exceeds some threshold? Should the framework run something like lint on your source and slap you on the wrist when you do un-MVC things (whatever those are)?

More to the point, what would be the benefit of all that finger-wagging? Aren't we trying to write applications that please our users?

Dan Davies Brackett
  • 9,811
  • 2
  • 32
  • 54
  • Seeing all the newbies writing bad code that some of us need to work with or rewrite, yes, I would like something that slaps your wrist. – Andrei Rînea Aug 06 '09 at 19:55
  • The reason I asked the question of how you wanted that wrist-slapping implemented was, I suppose, to illustrate the difficulty of doing so in any meaningful way. – Dan Davies Brackett Aug 06 '09 at 20:12