Welcome Guest, Not a member yet? Register   Sign In
At what point do you seperate things into different models?
#4

(This post was last modified: 06-20-2016, 09:19 AM by PaulD.)

This is a good question but it is caused by the idea that a model should relate to a single table in the database. I have never found this practical or to be possible in any real sense exactly because of joins, except in the most simple of applications.

I recently changed to using models as far more complex entities, with thin controllers. So the controller would call a Product_display_model say and give it the range it wants. The Product_display_model would get the range, all related products, and return the data for the page. A Product_management_model would be used for adding and updating products etc. A Basket_model would be responsible for the shopping cart, an Order_model for dealing with orders etc. All of these would interact with the product table, range tables, order tables etc.

For more complex patterns I would use libraries too, but for a shop it can be managed well with just models.

The design of the different models' areas of responsibility is quite critical here. Sometimes it is easy to divide them up as in this case, but if you get it wrong, revisiting it and reworking it can be a real pain, and often a complete rewrite.

Now my controllers are very thin. They just do the 'who is this, are they allowed, what are they asking for, what views do I need' and then output the page.

Best wishes,

Paul
Reply


Messages In This Thread
RE: At what point do you seperate things into different models? - by PaulD - 06-20-2016, 09:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB