ASP.NET MVC fuzzy path to the pit of success?
I'm interested in adding ASP.NET MVC to my skillset. However my reticence comes from the fact that there seems to be a lot of "fuzziness" when people talk about implementing applications and how to adhere to the rules of the MVC architecture. I've heard Microsoft quoted as wanting developers to fall into the pit of success. With that said my question(s) is:
How do I avoid writing bad MVC code when there is such a variance in the agreement on how a pro开发者_JS百科gram's structure should adhere to the tenants of the MVC architecture? Is there an agreed upon approach/best practices?
Would I be better served to learn Ruby on Rails(other than to learn a new language) to get an understanding of what inspired Microsoft to create ASP.NET MVC?
Go through the NerdDinner tutorial. It is a step-by-step walkthrough of the process that was used to create NerdDinner.com using ASP.NET MVC. There is general agreement that this application (for the most part) follows best practices in its design and coding.
Also, have a look at Scott Hanselman's File/New/NerdDinner presentation at Mix09. He builds the entire application (more or less) in 70 minutes, with wit and insight. Scott also talks about some of the important surrounding technologies such as jQuery.
You'd probably be better off becoming familiar with the MVC architecture itself. Learning about Design Patterns may help, as MVC can be seen as a composite of Observer, Strategy, and Template method.
MVC has slight nuances when viewed from ASP.NET MVC, RoR, GroGR, CodeIgniter, etc, but it's all essentially built around the same concepts: business logic goes in the model, controllers serve to route to appropriate models, and views should just display data. While there are differences between MVC 1 and the web centric MVC 2, once you understand MVC you can use different implementations of it fairly easily.
Here's a fairly good explanation of it from a software design course.
There's no single right way in doing object-oriented programming at all. Just pick the one that is closer to your taste. And a year after that, your taste will change... that's how our programming skills grow ;-)
For example, RoR takes ActiveRecord path while I personally prefer domain-driven design with POCO business objects. But this comes from my, sometime unconscious feeling of proper OO design. Yours may vary - but that's the exact point, only you can decide what's right for you. And, of course, don't forget that your customers want it now ;-)
ASP.NET MVC is a ripoff of Ruby on Rails in my opinion. I don't mean to sound harsh, Microsoft has done an excellent job and it's a great platform. But it wouldn't do much good to learn Ruby on Rails to see the roots of MVC, they are extremely similar.
That being said, you should really learn the MVC architecture and I would recommend you learn ASP.NET MVC. I think it is very good in certain scenarios, a great separation of business logic from the view.
精彩评论