OOD In an MVC Land

If you are familiar with asp you are probably familiar with the concept of code behind and more recently MVC. Over the years I have bounced around using many different languages, frameworks and technologies. Using the pattern in another language emphasizes that this is best implemented as a conceptual pattern. OOD is best done first if you have any logic at all. If you are just editing a list and it IS just a CRUD app, an MVC up front approach might work fine. Every where I look the MVC is pushed as THE solution. When, like any other design pattern, it is never more than a piece. Try to think outside the MVC box and do what works. Don’t try to cram everything you want to do into the MVC or you will then need to create classes called ‘helpers’ and then the only business object you really have is the MVC, and you might as well have not done OOP in the first place, and you should have stuck with Clasic ASP or PHP4 and your procedural, monolithic methodologies.

Remember to keep your business logic out of your display logic. If you call it a template or a view is up to you. Just don’t be caught with your pants down when you find out your model is hard-coded to your business logic. Or worse, you find application has become a big string of classes that are untestable and codependent on your control structure. I always keep focused on being loosely coupled and dynamic without being magic.
Which brings me to the ASP MVC.NET implementation. As with many things in .NET, it seems to be a situation of ‘we want that buzzword tech. too!’. There are many advantages, and as usual I get the feeling it is a step in the right direction. Also not a surprise, it feels like it is not what is supposed to be. Like the point was lost in the translation. The .NET crowd wanted Ajax, they got the word but missed the point. their websites were freed from having to load the whole page, but they still were cursed with throning the state string back and forth and never got the benefit of good efficient client side processing with JavaScript.
Oh man, I don’t want to get started on JavaScript in the MS camp. Almost all the MS shops I have talked to in the last year think ‘Java’ and ‘JavaScript’ are terms that are interchangeable. To their credit, for all they knew of either they might as well be.
Then the .NET crews whined about not having flash, so they got Silverlight. (which I like what I have seen, but why cant every one just love SVG???)
My largest point of contention with ASP.NET is that all the training and documentaiton pushes you to use the built in controls. The built in controls are obviously not meant for the Internet, but are for LAN apps. Thus ASP.NET is best suited for application developers moving into the Web Interface realm. I once saw a ASP.NET application that fed 6MB HTML (not including graphics) at the user. This was the worst case, but was far from atypical.
Enter the ASP MVC. None of the state dependent controls work. Pat them on the back for destroying the only thing the rest of the web development world envies them for. Wait, this isn’t a totally negative rant. ASP MVC encourages you to be conscious and intentional with your HTML. It also opens the door for using jQuery instead of Microsoft Ajax. Thus, as far as the client/browser side you are free to do as you please.
But, then you may think that all is well. Until you start dealing with the server side. I am not going to get down on it, since it is still in development. Although, as with any software if it is out of development it is dead, so take that as you will. The real problem that I do see is that it tries too hard to be an MVC. Your Controllers end up getting huge with ‘actions’ (and where is that /really/ in the pattern). There is only one layer of organization in the controller. This means you cant go beyond controller/action. Granted you can customize your routing, which feels like you are configuring someone else’s app, instead of building your own. Then all your views tend to be one per action which defeats at least the bulk of the benefit of application and presentation separation.
Hear again, another MS team tries to step in and save the day. The Entity Framework (EF) is the official flavor of the day. This essentially is your ORM Model to supply your CRUD. None of which lend themselves to good OOD. You still are encouraged to draw up a action that feels oddly procedural mashing your EF object lists into a view. EF does not allow for any type of static extension so there is no natural way to build business objects. The solution to this is to just build your business objects facade over the EF ORM. But no examples encourage this, neither does any of the community publicize this. So you should shove your monolithic processing in an action and pray you can rewrite instead of maintain. Now to add to the sadness of it all, there is no straight forward way to call and render an action from another controller. So now that you have a huge controller class you now start copy and pasting code between actions. I have seen Quick Basic apps that are better.
Maybe I am just jumping the gun. It is still in development after all. Maybe the ASP MVC community will get there.
Currently the way I am dealing with everything is having a nice thick jQuery driven client. I load partial views in via Ajax and call JSON services. No community so far has dogged the MVC fail bullet. I just want to know when everyone is going to move on from MVC and realize OOP != OOD

Advertisements
OOD In an MVC Land

4 thoughts on “OOD In an MVC Land

  1. Hi. I used to be a .NET developer in my earlier days, but moved over to PHP a couple of years ago. When using a web based MVC framework, the language you use doesn’t really matter, since you are always going to be constrained to the way the framework perceives that MVC should behave.

    This leaves developers with a great amount of responsibility, especially when designing object orientated applications. The problem I’ve noticed with MVC frameworks, is that they tend to make us think that OOP and relational databases work the same way. This can be easily spotted when using ORM, where the mapping to the objects are very tightly coupled to the database.

    At the place I work, we’ve ventured into the land of domain driven design. (http://en.wikipedia.org/wiki/Domain-driven_design). Which is really a way of separating the objects from the storage, thus allowing us to use our models like we want to, making it behave as classes and not being limited to the way our storage engine wants us to.

    This is a bit of a mind shift in one’s thought patterns, but I agree with your article that doing an application in an MVC environment isn’t really the same thing as design an application.

    1. drydenmaker says:

      Yes that is really what I am talking about here. Object Oriented Design is the non-buzz (or pre-buzz if you will) term. Object orientation conflicts with Relationalism. As far as I have seen in my 26 years programming ORM is a sketchy concept at best. Even worse is how many implement it. The relational model often finds its way to the UI. Which may be fine, but why not give them the query browser for whatever RDMS you are using and call it good. Give them Cristal Reports, SQL Reporting Server, Oracle Reports, or PhpMyAdmin. That is what all those do. Or else build an application.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s