tags:

views:

69

answers:

3

I have two different models that need saving; a TextFile object and a static Settings object.

Right now, I have the save logic implemented in the models themselves.

I like how clean this looks, when calling the save methods:

Settings.Save();

and

_currentFile.Save(filePath);

However, from what I have read it sounds like I am supposed to implement the Save methods in the ViewModel.

Is what I am doing right now improper?

+2  A: 

Saving goes in the model. But, it might not go in that particular class (the Model consists of all of your actual workload).

The ViewModel only exists to translate from the Model to the View. It should have no business logic.

kyoryu
+1  A: 

If what you are doing is persisting the state of one of your models to a file, then I would say what you're doing is perfectly logical. If the file you're saving is saving data this is view-specific, then it really should go in the ViewModel.

Steve Danner
A: 

You might be interested in the Writer sample application of the WPF Application Framework (WAF). It uses the MVVM pattern and it shows where the Save operation can be implemented. Additionally, it uses a static Settings object to save the user preferences (language).

jbe