5

I'm building a WPF/MVVM application that takes input from the user and generates an output document which it saves in a temporary folder and opens for display in the native application (e.g. MS Word). The document's data is, of course, represented by the model as well as the logic for constructing the actual document (including the interaction with a third-party library that works with document file formats).

My question is: should the actual file save-to-disk operation be in the model? Or should it pass some kind of object (stream, possibly) back to the view model so it can be saved to disk there. Where does something like that belong?

1 Answer 1

3

The Model is meant to represent both the current state of the data and the data access layer that represents the content. So, if you were using a database, you would handle read/write calls there. In that same vein, you should do disk reads and writes in your model (or, at least I would).

5
  • 2
    +1 Today its a WPF app, but tomorrow who knows. Any logic you dont want to lose when you move to a new UI should be in the model (business layer).
    – Andy
    Commented Jun 17, 2015 at 1:51
  • @Andy -- fair point, but, as I suggested in my question, the operation could also reside in the view model which is not part of the UI. I'd never consider putting the disk write op in the view.
    – rory.ap
    Commented Jun 17, 2015 at 12:07
  • 1
    @roryap no, your VM is part of the UI layer. Its the glue between the view and model, and what you put in it will be heavily influenced by your UI technology.
    – Andy
    Commented Jun 17, 2015 at 22:37
  • @Andy -- I disagree with that statement. In a well-designed MVVM, the VM knows nothing about the view, which makes it easy to test and also to switch out the UI later without affecting the VM.
    – rory.ap
    Commented Jun 18, 2015 at 14:09
  • @roryap You may disagree all you want, but the VM being part of the UI layer. "the view model is more model than view, and handles most if not all of the view’s display logic" Display logic is not business logic. en.wikipedia.org/wiki/Model_View_ViewModel The VM is in place of a controller in MVC, yet I doubt anyone would argue the controller is not part of the UI.
    – Andy
    Commented Jun 18, 2015 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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