Jump to content

Alternative to MVC


Cardale

Recommended Posts

If you're looking for an approach for building web applications, then MVC is the most well known, and probably the most natural way of accomplishing this. It just makes sense to separate the data layer, from design, from business logic, which is what MVC attempts to accomplish.

 

If you're looking for more general design patterns that just promote good application development, ease of maintenance, etc etc. I was actually just reading through this article the other day. It may provide a good overview and help get you thinking along some new lines. Please post any new thoughts/questions as they come up, as debates and rants on the topic prove to be quite insightful.

 

Here's the link: http://www.ibm.com/developerworks/library/os-php-designptrns/

Link to comment
Share on other sites

 

I know that sometimes (when I am tired) I design my stuff without the controller.

 

(Model + View + Controler = MV)

 

hehe  ;D

 

I don't see how you could do that becuase whatever else you create to link the model to the view is going to be a controller.  i mean use could just do a view and controller or even a model and controller but not a view and model.

Link to comment
Share on other sites

Yea, really if you try creating any large-scale applications in PHP, you're more than likely to quickly realize the strengths of the MVC approach to things. Of course, with PHP the seperation between the view and controller is much less clearly defined (html view/controls; obviously seperating the controls from the layout is possible but might be more burdensome a task as far as agility is concerned than is worth the while), but nonetheless it's an excellent methodology to use for developing applications. Consider Ruby on Rails, basically an MVC-generating platform for web applications. In RoR, the Model and View were realized to be so closely intertwined as to have lent to the creation of the 'ActionPack', which is basically both in a nutshell. Anyway, I'm kind of ranting but I was really wondering, if not MVC what is it you're looking for more of? Just ideas in general/brainstorming or is there something lacking you're looking for?

 

Personally, as of late I've found that MVC works quite well, especially for internationalization and AJAX/non-AJAX platforming via the controller seperation. The classes get quite hefty in function name/number once you start breaking everything up view-/controller-wise, but it really does work well as far as scalability and manueverability once the projects get large.

 

Anyway now I'm just ranting. Hope this sparked some thought :)

Link to comment
Share on other sites

Well I was just reading about MVC and I wish everyone could sum it up in about three sentences instead of endless paragraphs and code and bull.  I just wanted to expand my understanding of where this is coming from and if any other design ideas existed.  That article from IBM was good.  Now I'm starting to notice a few comments about that being factory and that being what ever.  I guess I'm just trying to move my understanding from coding little individual snippets to coding large scale projects on top of learning new PHP5 features.

 

Is MVC basicly Model = The generic functions that need to be performed V = The template C = The controller is the handler of the model aftermath?  What is it summed up in a nice little paragraph

Link to comment
Share on other sites

I wrote this small example for someone a while ago, that might help a bit.

 

Its not meant to be working code (never tested it) so I wouldn't ry it, but it might give you an idea.

 

I still stand by what I said in that thread. Download the codeigniter framework and follow there 'Getting Started' guide, it will all make sense.

 

Link to comment
Share on other sites

I think I understand.  How do you decide whats what in terms of each logic type?  I think thats what I will struggle with most.

 

Model = Database Information or just database connection? V = The Presentation having multiple presentation classes for each individual object is good? or just one generic?  One generic would be faster but might limit? C = The interpretor the actual application our little modules?  Shouldn't it be MCV?

Link to comment
Share on other sites

Shouldn't it be MCV?

 

The way I look at it, it probably should be CMV.

 

The controller is the entry point to the application, it is the file the client actually requests.

 

Theres usually two controllers (as in my example). The front controller is the entry point and it takes the parameters passed to it and decides which action controller to execute. The action controller is then responsible for making requests to the model, the model then sends data back as a response. This data is then merged into the view then the view is sent back to the client as the finished product.

 

Again I say, I am no expert in this field, and this really is my own interpretation of the pattern. It can be implemented in a few different ways I suppose, and I'm sure it could also be done without the action controller that I used in my example.

 

I'll also say again that I think its a really good idea if you are interested in seeing the benefits of this pattern in action to download one of the already existing MVC frameworks and doing a few tutorials using it. I suggest code igniter because it is small, the code itself is very easy to follow and you set it up and read through there 'Getting Started' guide in a single afternoon.

 

I've never actually used codeigniter for anything, but played around with it for a few days prior to starting to build my own framework.

 

Of course, all this talk of frameworks.... you don't necessarily need any framework to implement the MVC pattern, you can use a simple MVC implementation in allot of small/simple web apps.

Link to comment
Share on other sites

Model = Database Information or just database connection?

 

Not necessarily a database, but just the data layer. You could be reading from an XML file or you could be parsing an RSS feed from an external source (well, that's actually reading from an XML file as well, but whatever) for instance. In the MVC pattern you'll never access the data directly from outside the model because it's encapsulated within the model.

 

The front controller is actually not a part of the model-view-controller pattern, but rather another pattern itself. However, you'll often see that pattern used with the MVC pattern as you'll need something to call the controller in MVC, and I suppose the front controller is the most convenient way of doing it, at least in a web environment, so you'll often see the front controller acting as an intermediate between the user and the controller in MVC.

Link to comment
Share on other sites

Now that I'm getting deeper into MVC it seems like a few basic classes are pretty helpful like a loader for models and controllers which is actually a controller if your using a framework to load them....its kind of confusing but its working pretty well although adding all this makes coding way more confusing.

Link to comment
Share on other sites

You either use MVC, or you don't. You don't have to use anything. MVC is a design pattern, a guide for a commonly occuring situation or scenario. If you are setting out to design an application with MVC, you have already caused yourself problems as you do not yet know if MVC is right for your situation.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.