tags:

views:

221

answers:

3

at the moment im integrating ORM (doctrine) into a MVC framework (codeigniter).

then it hit me that this was the obvious way of setting up a MVC:

the controller calls the models that are representing database tables.

look at this picture:

MVC + ORM

then i wondered, how can a MVC without ORM be real MVC? cause then the models are not real objects, rather aggregations of different functions that perform CRUD, then returning the result to the controller. and there is no need for a state (object properties) i guess so the functions would be all static?

correct me if im wrong on this one.

i guess a lot of people are using models without ORM. please share your thoughts. how do your models look like?

+3  A: 

MVC has nothing to do with objects. That makes it quite simple to have MVC without an ORM.

Georg
@Gordon: No, I meant what I said. You can use the MVC pattern without programming with any objects.
Georg
+7  A: 

MVC is a general purpose UI pattern originally conceived for OO languages (I believe Smalltalk was the first).

If you don't have a relational database as a back end (say, a binary serialized file format) you have no need of an ORM layer.

The two are quite distinct and can exist without each other.

micahtan
ok, then i get it now that they are different things. and regarding my second thought, a model without orm is just an aggregation of static functions that perform CRUD? not a real object/class?
never_had_a_name
ORM is just a mapping framework from a relational data store to objects: no class structure is implied. It can be an aggregation of static utility functions, but it can be organized differently. The complexity of the ORM generally depends on the complexity of the operations it supports (e.g. batching, object dependencies) and richness in how it describes those objects.
micahtan
+1  A: 

What about applications which don't use a database but use some other serialization for their data (such as writing out an XML file)? MVC and ORM are orthogonal concepts. MVC is about how you organize your internal object interactions, and ORM is about how you serialize and deserialize the model. You can certainly use MVC without ORM by simply substituting a different serialization method.

The controller part of MVC is not about making the low-level calls to serialize, it is about tying together views and models to create the proper user experience and task flow.

Michael E