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?

asked Jun 16, 2015 at 19:59

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).

answered Jun 16, 2015 at 20:29
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). 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. 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. 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. 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. Commented Jun 18, 2015 at 15:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.