tags:

views:

215

answers:

6

I know that an MVC framework allows you to separate business logic, data base access and presentation, but why do we need a framework to do this.

Can't we just keep our classes separated, perhaps using different packages/folders for the model, view and controller classes?

+3  A: 

An MVC framework is a framework written to split up the the business logic, database access and presentation.

This is very useful in most web applications, and now lately into software/desktop applications.

This is due to the fact that following the MVC model, your code will be much clearer, cleaner and you keep your application DRY (Do not Repeat Yourself).

You can write your own classes and separate them into Model, View and Control. But again, you will need a framework to help you in accomplishing certain tasks. Like a List control in ASP.NET, or PHP framework being able to help you translate text between languages and so on. (Oh why reinvent the wheel?!)

thephpdeveloper
The original MVC was actually designed to support classic text-based applications, and later desktop applications. Its advent in the web world is much, much more recent, and generally the last to get useful MVC frameworks.
jrista
A: 

You can of course approach it yourself by segregating your classes. A framework supplies common scaffolding that you wouldn't have to build yourself. But it will also impose some structure on your code. You'll have to evaluate whether the framework helps more than it hurts.

Ned Batchelder
+3  A: 

MVC and framework is a different thing. MVC is just an architectural pattern, which can be applied with any project, with or without framework.

So you don't need a framework to do this. You can separate them by yourself. :)

Sikachu
+7  A: 

In my opinion the thing you are talking about is the MVC pattern and not a specific framework. Of course you can go and keep all your classes within one project and still use the MVC pattern, as you have all your UI code in the views, the logic in the controllers, ...

A MVC framework on the other hand makes it easier for you to use this pattern. It may provide some base classes for controllers and a mechanism for the communication between view and controller.

I don't know if you are familiar with ASP.NET MVC. The framework itself is very small, but it helps you developing an application with the MVC pattern, as you don't have do think about the previously decribed areas...

Hope this helps

ollifant
A: 

You are correct, there are strategies that you can implement to help with separation of concerns without using MVC.

Microsoft's ASP.NET MVC framework is one strategy that can be employed, and that is what I think you are asking about. This MVC framework makes such separation of concerns easy.

The other major advantage of MVC is testability - (depends on whether you believe in unit testing - I do).
The MVC framework ensures that all orchestration logic is on your controllers and through the FormControls collection allows full unit testing of all aspects of your application except for how it is presented.

As the MS MVC framework encourages adherence to common rules and structure of the application which should lead to greater maintainability.

The major downside of MVC is the code-in-front code weaving required for presentation, but this can be easily overcome.

Mike
A: 

Perhaps this is just a linguistic thing. I've seen "frameworks" referring to themselves as a DSL -- Domain Specific Language.

And you don't need a framework But here's something to consider: You already know for a web app you're going to want to do a few common things... route URLs, render pages, etc. Why re-write it all? For other problem domains you'll have generic things to do as well.

T. Stone