Online Games Grumpy Unix Fart Contact Us

Model View Controllers

Quite a great deal has been said about the model view controller design pattern, usually followed up by pointers to packages and frameworks we're supposed to use because they make our lives easier.

While I'm all for code re-use, I do think it misses the point.

I've written many model-view-controllers through the years, some of them optimized for the quick-n-dirty cgi scripts, others in PHP, some designed for database access and still others for vanilla code. I've written model-view controllers customized to handle several actions on a request (in that case, an XML document containing instructions).

I will be introducing one of those implementations here, one that I've named GenieMod (for lack of a better word)

MVC is not a framework

It is an idea, one that if followed, will indeed make life easier (and less problematic in terms of trying to figure out what is going on) I'm not going to delve into them too much here. If you are new to the idea, you can take my two cent tour of MVC .

What I will address is this crazy notion that some how, MVC means using a package and then forcing your application into that model.

Now, to compensate for this problem, people who make MVC frameworks try to think of everything, and, they do. This one-size-fits-all MVC idea leads to larger, often bloated applications.

If instead, MVC were treated as an idea, you would design your own MVC custom fit to your application.

The view is part of the application.

Templates are fine, but they are not the same thing as the view. The view is a portion of the program just as the controller or model might be.

The difference is, the view tends to involve HTML output, consequently people often think of a view as a template system. It is not. For all intents and purposes, a "view" could be a code reference, pointer to a function, object instance, etc..

The view is a part of the program.

Don't be afraid to write your own.

Unfortunately, there has been a real stigma against coding up your own packages in recent years. The thinking is, if you don't use CPAN/Pear/Jakarta/Whatever for everything under the sun, you are some how inferior.

Rubbish! Go ahead and re-code something if it suits your purposes. Go ahead and get your hands dirty, go ahead and use the source. Afterall, what point is there in having access to source code if you never take advantage of it?



Now, I'm hardly suggesting we re-write everything, I often re-use modules, sometimes as modules using object oriented designs and other times, I'll just borrow the relevant bits of source from the package.

Code reuse is your friend not your jailor.

Send to a friend

[add]
Please enter code (Change Code)

Sending Message.