Role of Model

tmay's Avatar

tmay

10 Oct, 2011 07:57 PM

I am having some issues in deciding what the roles of my models should be. For example, I am creating an application that has a tool for managing recipes. The data contains categories that have subcategories that have recipes. The tool allows for rearranging and deleting things. The updates will not be committed to the database until the user clicks a save button. I am wondering if I should be updating the model when changes are made, or be updating VOs and not update the model until the data is saved. Right now, the model would not be used outside of this one area and the data is refreshed when this view is loaded to prevent stale data (multiple users can submit recipes); so if the approach to take is not to update the model until a save is done, I am wondering if there is any point to my model. I like the idea of using commands and my model to perform this logic, but am not sure if the model should only represent the saved data. Any advice would be greatly appreciated.

Thanks,

tmay

  1. Support Staff 1 Posted by Till Schneidere... on 10 Oct, 2011 09:56 PM

    Till Schneidereit's Avatar

    If I understand correctly, your model will automatically be reverted
    to the old state if you leave the page, making it impossible for
    unsaved changes to accidentally escape from it, right? In that case, I
    don't see any problems with immediately updating the model instead of
    keeping changes somewhere else.

    If, on the other hand, you want to be able to do partial roll-backs on
    the model's data, I would keep some sort of change list in addition to
    the model itself. But either way, I think using a model is the right
    thing to do here: It can make sure that your data is always kept in a
    valid state and that change events are dispatched and can be managed
    by other parts of the app, should the need arise. Imagine, for
    example, the later addition of some sort of change view or a view
    showing a condensed version of a recipe.

    Depending on how exactly you partition your model updating logic, the
    line between VOs and models blurs quite easily, anyway: If you keep
    all of your updating logic and validation in commands, the model
    effectively becomes a big VO. People have very different philosophies
    on how that partitioning should look like.

    hope that helps,
    till

  2. 2 Posted by tmay on 11 Oct, 2011 05:38 PM

    tmay's Avatar

    That sounds like a good solution. Thanks for your help.

    Thanks,

    tmay

  3. Support Staff 3 Posted by Till Schneidere... on 11 Oct, 2011 06:10 PM

    Till Schneidereit's Avatar

    glad i could help

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac