My program uses MVC. When the user hits “New File”, I need to check if the previous open file is edited (and prompt the user to save if so).
From what I’ve understood, the controller should solely perform all validation and logic. Is it then okay for my controller to prompt the user for file name, save previous file etc using JOptionPane? Or should all input be taken in the GUI?
Thanks!
In the MVC pattern, “The controller receives user input and initiates a response by making calls on model objects”.
Considering the context of your problem, especially the tasks which you mentioned:
To help you better understand, I’ll tell you what task should be performed by which component.
Your model should have logic for performing 2 and 3. And your controller should invoke (call methods on) your model and depending on the returned values invoke yet other functionality on the view, like a using JoptionPane and other such things for prompting the user for file name etc.
So all in all, your controller should only act as a moderator and do nothing on it’s own. All the tasks you mentioned will be performed either by Model or the View. It’s the job of your controller to bring them about.
Good luck.