0

In my Application (with MVC-pattern) I display the content of Text-files from a directory. The path's of the files are stored in the Model and I want to change the current Directory.

Is it better practice to create a new Model and tell the View, or to clear and reload the current Model?

SeRup
  • 1
  • 1
  • 3
  • 1
    No. It is unnecessary. Your model needs to have something like `removeAllFiles`, `addFile` methods. Each time you change directory, call `removeAllFiles` and then recursively get all files in the directory and `addFile` method on the model. That will update the model. – SomeDude May 01 '17 at 20:33
  • For [example](http://stackoverflow.com/a/14837208/230513). – trashgod May 01 '17 at 21:06
  • That's a matter of context, for example, based on your context, is it faster to load the directory contents each time or would maintaining a cached instance be more efficient. That would mean, that when the user backtracked up to the parent directory, you wouldn't have to (immediately) refresh the model. Another question would be, do you want the model to be mutable? There are times when making the model mutable isn't a good idea, because it's not the responsibility of the controller/view to mutate it. There is no "right" answer, you need to take into consideration the factors you have – MadProgrammer May 01 '17 at 21:45

0 Answers0