[OT?] MVC pattern: controller / model responsibilities

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Hi all,

For a current project I am building a sign-up process using the MVC
pattern. In the past I've used MVC similar approaches, but never fully
OOP. (Read: too much responsibilities in one routine, etc.). I really
want to get a better grasp of the MVC pattern with a genuine OOP
approach. I am little stuck on the responsibilities of the different
entities involved though.

In short this is what it is supposed to do:

User tries to sign up
- Start db transaction
- Insert sign up info
   - Success:
     - Log it
     - Mail user with validation info
       - Success:
         - Log it
         - Commit db transaction
       - Fail:
         - Log it
         - Rollback db transaction
   - Fail:
     - Log it
     - Rollback db transaction

These procedural logics I think are pretty common. You could debate
whether Logging every event is needed perhaps or maybe debate some other
stuff. But please try to keep the general idea in mind. The difficult
part at this moment for me is to determine what routines are handled in
which components.

Right now my approach is:

- ControllerSignUp->signup() checks the form validity
- If valid data, hand it over to ModelSignUp->signup()
- Model->signup() checks availability username / e-mail address
- If valid data, hand it over to ModelSignUpTable->insert()
- If succeeded / failed, log events through ModelSignUpLogTable->insert()
- Report back to ControllerSignUp
- If succeeded, ControllerSignUp mails user

... But as you perhaps can see, here is where it gets shady. Cause if
the mailing from the Controller fails, I can't easily let the Model roll
the transaction back again.

Then again, I'm not sure if the Model should be responsible for mailing
the user, or perhaps even logging the events in the first place. Right
now, I have a specific ModelSignUpLogTable, but perhaps I should make a
general ModelLog with a ModelLogTable?

What would be your approach as far as implementing aformentioned
responsibilities are concirned?

Thanks for your insights.

Site Timeline