views:

154

answers:

4

We are build a website using MVC pattern. So far all the pages we built used models which had to operate on Reference data(which is cached when the website loads for the first time). But now we have reached that stage of the flow where we have to deal with Transactional data (which is specific to that flow). Till now we created model classes by giving it all the data, since they were all cached already. But now that we have to deal with transactional data, should we do the same thing where we get all the data upfront and create a model object or should we make the model class get the data by making service calls.

A: 

The disadvantage of the first approach is that the data that is fetched upfront might never be used. So we went with the second approach where the model gets the data. To decouple the model and the service calls we used a interface. Alternatives are welcome.

Nazgul
This isn't really an answer. This is more of an edit to your original question. You might want to edit your question and add this.
S.Lott
A: 

Model objects are built through queries to the database. That's the general approach.

Model objects can be built through web services requests to other servers and databases. That's almost the same thing.

If -- for some performance tuning -- you pre-build all the model objects, fine. That's a special case.

I prefer to use am ORM layer to handle object caching, so I don't prefetch anything. Rather, it stays in the ORM cache.

S.Lott
+1  A: 

If you're truly using MVC, then your controller should intercept the particular action that should be taken, invoke any data-related requests, and shove the data into your model objects so that the model can then be placed into the view. There is very little benefit to having the model populate itself from a database, because you already have a controller which can do the job in a more cohesive manner.

MetroidFan2002
A: 

In true MVC, the model is responsible for updating itself in reaction to an instruction from the controller. As such, yes. The Model, and only the Model, should make service calls

Vihung