VCSM - An SOA/RIA Friendly MVC Upgrade
Anyone who's done any web-development in the last 5 to 10 years is probably familiar with (or has at least heard of) the MVC (Model-View-Controller) design-pattern. The pattern is adopted by more-or-less every notable web framework in every development language, from PHP to Java to ASP and to Flex.
In its simplest form MVC is merely a separation of layers, i.e. the Model is responsible for data access (be it from a DB, a CSV file or a Web Service), the Controller is responsible for encapsulating business logic surrounding processing of user actions, and the view simply represents information passed back from the controller to users in different forms. An MVC solution has the advantage that you can theoretically change any of the layers independently of the others.
This pattern has worked well for traditional web applications, but some frameworks and developers are beginning to struggle with how to fit in SOA hook points or RIA toolkits into the mix. I've rencetly started using the Zend Framework for a PHP project and going through various online tutorials on Dojo/YUI/Web-Service integration reveals a lot of different approaches to the problem. Whilst this isn't really surprising, especially in PHP-land, I thought perhaps a more generalized architecture would help develop better new-age frameworks.
What I have in mind is a View-Controller-Service-Model architecture (I never liked how MVC names the Model before the View even through these two never talk directly to each other). In this design, the new Service layer is the business-logic wrapper around the raw Model, encapsulating all functionality into discrete functions. Controllers are then demoted to simply calling the relevant Service operations and perhaps performing some customized error-handling or data transformation in preparation to pass to the Views.
Having a clear separation between a Controller and a Service means the Controller is independent of the operation being performed or the application invoking the operation. This frees you to create server-side PHP pages using the vanilla Zend Framework MVC implementation or rich client-side pages using your favourite toolkit that bypass the server-side controllers. The end result is greater flexibility in hot-swapping interfaces, which also means your application is integration friendly (depending on how you design the Service layer, I'll give an example of a simple, multi-format PHP implementation in a later post).