Models, controllers, and code reuse

Posted by user11715 on Programmers See other posts from Programmers or by user11715
Published on 2011-02-25T22:17:11Z Indexed on 2011/02/25 23:33 UTC
Read the original article Hit count: 407

Filed under:
|
|

I have a blog where users can post comments.

When creating a comment, various things happen:

  • creating the comment object, associations, persisting
  • sending notification emails to post's author given his preferences
  • sending notification to moderators given their preferences
  • updating a fulltext database for search
  • ...

I could put all this in the controller, but what if I want to reuse this code ? e.g. I would like to provide an API for posting comments.

I could also put this in the model, but I wonder if I won't lose flexibility by doing so. And would it be acceptable to do all of this from the model layer ?

What would you do ?

© Programmers or respective owner

Related posts about design

Related posts about oop