I am implementing a model design where DB tables are 'resources', and a model can use many 'resources'. When I return a row from a table, it is represented by an 'item'. (This came from a book by Keith Pope, but I've seen it in several other places too).

So, my question is, who should be able to access the resources? In particular:

  • From time to time I'm tempted to let controllers access the resource directly, rather than through the model, for very simple tasks like finding a record. Is this OK?

  • Many of my resources are accessed by more than one model. For example, the 'country' table is accessed by the Organisation Model, and the User model. Presumably this is OK?

Any pointers appreciated, as always!

migrated from stackoverflow.com Aug 10 '11 at 18:55

This question came from our site for professional and enthusiast programmers.


Your "resources" should be abstracted into a repository class. Your controllers can access the "resources" through the repository. This gives you the ability to change the underlying "resources" model, without breaking the application. It also gives you a place to put in some security, as needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.