My new pattern (MVPC)

Here’s the pattern I have been building with lately and having the most success with. I use bare html files and css file as my “View”. Next I have Javascript files doing all my logic, now I get a lot of pushback from the MS-MVC and Rails Zealots that I am muddling up logic and view.. I strongly disagree and from what I have seen of how both those frameworks get used this approach is much much cleaner and simpler. The mental leap you need to make is how you will have to split your controllers. First Make sure you put all javascript in their own .js files (future proof for Content Security Policy) and just make the jump in your mind that those .js files are your presentation controllers and consume the JSON from your WebService. Again this is different from the MVP model in that those JS function can modify the view based on actions on the page. And now on the back-end make your WebService layer your data controllers and model. All data changes and reads must be made through that layer.

Advantages to this approach

  • Testing of Model layer becomes much easier
  • API ready for partner support
  • Add other clients web,smartphone,tablet,desktop with ease
  • True design¬†separation¬†(finally!) – designers only work with html and css
  • Fast and Lightweight
  • Swap out CSS with ease for themes and other device support
  • No dependency on proprietary frameworks
  • No dependency on proprietary backend (swap out WebService with ease)

Now some like to take this a step further and use Knockout.js to put data binding directly in to the view, I prefer to keep all data binding and logic out of my view and deal with that directly in my Javascript. My desire is always to keep the view as pristine to the designers original as possible, and makes debugging way easier.

Comments are closed.