Tuesday, February 12, 2008

A New Way To Think Of MVC. Introducing PBVC.

Yesterday I argued that companies need platforms in order to maximize their flexibility to respond to the demands of the market in the fastest possible way. Today I thought that many of you could perhaps benefit from from some more specifics. 

When you think about developing an application, many (most?) of you will think of implementing some version of the MVC design pattern which stands for Model View Controller. The MVC pattern specifies a way to separate the user interface (View) from the data (Model) using a messaging or event system routed through a Controller. But the MVC can be implemented in many ways, and the key to a good MVC implementation is what exactly the model is.

The model essentially represents your data. But does it represent data in a form that just reflects how you store the data in the database, or does it represent data in a form that reflects what makes most sense in the context of what your application is trying to do. When the later is the case, we call the data representation business logic.

Business logic typically handle requests for data by grabbing raw data from a database, modifying or combining that data with other data, and presenting that data in a way that would be most useful to the user interface code because it reflects the real application model instead of just how the data is stored in the database.

And so here we get to the core of what I am suggesting.

When I talk about the idea that companies need platforms, I am making a really specific argument about how to architect systems. What I am really suggesting is that the model be split into a platform, and business logic. The platform is designed to make it easy, or easier, to build and modify business logic.

What this means will be different for every company. But, to use a simple example, if you are a retailer, then perhaps the customer database, and the credit card transaction system are handled at the platform level because they are things that should always be the same no matter what. At a lower level, perhaps the platform also contains a data storage abstraction that handles all scaling.

Scaling is a great example of something that should never be of concern to someone focused on business logic. And the business logic developer should rarely be told that something can't be done because the system can't handle it, can't scale etc. The platform developer should be totally focused on serving the needs of the business logic developer by providing abstractions of core system functions and application requirements.

What we are really doing is adding one more layer to the MVC pattern. Instead of MVC, think PBVC, for Platform, Business logic, View, Controller. And while, on some level, this many seem obvious, the frameworks that many of us use do not suggest this level of granularity. And so while no MVC frameworks prevent this kind of layering, because of where frameworks stop, most developers will fully blend things that are platform related issues with things that are business logic, making code much harder to scale and maintain, and most importantly, slowing down reaction time in the marketplace. For many businesses that intend to scale and need to iterate rapidly, separating these two different layers and focusing on them independently can have a profound effect on the ultimate success of your business.

8 comments:

Mark Allerton said...

Hank, isn't this pretty much the goal of Enterprise JavaBeans and its many competitors/successors? I say "the goal" because if you're looking for a list of things that suck, EJB and its friends are pretty good candidates.

Apart from the idea of some common services (like the credit card processing you mention) how would you differentiate PBVC from these solutions?

(BTW, great blog, being a developer of roughly similar age and experience, I am so on the same page as you a lot of the time.)

Cheers

..Mark..

Hank Williams said...

Mark,
First, thanks much for reading. I love hearing from people like you.

Regarding your question, I have never really studied or worked with EJBs because I have never heard anything good about them, and they really only seem to ever be used inside big corporate entities, not startups. When I think of frameworks I am thinking of things like ruby on rails which seems to be such a major player in the web world, and PHP with cake, etc.

Regarding your question, I think the answer is, it depends. EJBs are a particular instantiation of something that might very well be able to implement the PBVC concept, particularly at a smaller scale.

But allow me, for a second to relate this to my current work. We have a platform layer written in java that speaks XML-RPC and is designed to speak to a business logic layer that also speaks XML-RPC. We have chosen a very generic protocol between the layers, and we are not tied into a J2EE container. The beauty of this is that as long as there is an entity that can take queries and return results, I dont much care how its internals are structured. Internally, our platform layer is actually a cluster of any number of machines inside amazon web services, knitted together with terracotta and other in house code that breaks problems down into smaller units and returns results. So in our implementation there is a lot behind our "P". But as long as thing are properly abstracted, that "P" could start out as nothing more than a mysql server and a little interface code, and grow into what one might really think of as a platform.

Mark Allerton said...

Sounds like an interesting implementation. My day job keeps me pretty enterprise-y, but I am quite into idea of doing "lightweight SOA" (which is what you seem to be doing) using Java without all the cruft (as opposed to Reddit's current Language Of The Week.) Also using AWS - I think the pay-per-usage model focuses your mind on the economics of the architecture in a way that doesn't happen when you can pretty much take the hardware for granted. I have a personal "science project" along these lines, might come to something one of these days.

Anyway, I guess my point was that PBVC is actually a pretty good idea, but not a new one. I think the difference between what you're proposing in this and previous posts and EJB is that EJB attempted to solve the general "business logic platform" problem in the general case (i.e all software vendors and internal enterprise projects) rather than the specific one.

I guess it's hardly a surprise that EJB turned out to be such a disaster - I know one thing that my time in the biz has told me is that it's a lot easier to generalize a solution to a specific problem than it is to create a general solution first time out :)

Hank Williams said...

"Anyway, I guess my point was that PBVC is actually a pretty good idea, but not a new one. I think the difference between what you're proposing in this and previous posts and EJB is that EJB attempted to solve the general "business logic platform" problem in the general case (i.e all software vendors and internal enterprise projects) rather than the specific one."

Indeed, there is very little that is truly new. Most things are just minor adjustments or reconceptualizations, but I think for people thinking "MVC" this is a different way to think. I think the real difference is that EJB is a specific implementation, not a design pattern. As such it brings with it a lot of baggage. By focusing on a specific implementation its hard to talk in more general terms. MVC is useful because it *isnt* tied to any particular implementation. I am not aware of any design pattern or general abstraction that addresses this issue (but of course I am *far* from suggesting that I know what all of them are)

Hank Williams said...

The other thing, in thinking more about EJB's is that they just represent the business logic and there is no concept of separating business logic from platform. What I am really suggesting is that EJBs not speak directly to a database, but to the platform.

michael said...

Hank, having the model speak to the platform is the right way to go. In solving problems, this issue, I think, really amounts to how to appropriate the stuff available. Having a great platform is nice, but to be really useful is to use the platform in a context. In principle, that context is supplied by the model-PBVC. I would only add that success will depend on users recognizing that the platform (with the context options enabled by the PBVC) provides useful 'moves' that fit the user's conceptualization of the problem they need to solve. [So a 'deep' model combined with a platform is a repertoire of actions that can be composed to solve the problem. It's like learning the moves available in a video game environment].

Mark Allerton said...

Hank,
The model not talking directly to the database was, in EJB terms, called "entity bean container-managed persistence". If nothing else, it's worth looking at why that didn't work out (entity beans being one of the parts of EJB that is now widely considered to be a mistake.)
Cheers
..Mark..

Mr. TA said...

Good news is, there is a solution to ASP.NET's problems: it's called the Turbo framework.

http://www.tasoftwaredesign.com/

Post a Comment