Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question

migrated from 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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