Hello
I hope this is not something very trivial and obvious.
I have some similar programs that I am working at. In each program I have to implement future about saving projects. I came with following design :
Project
 -- Program1Project
 -- Program2Project
The base class Project :
class Project
{
 public:
   void NewProject();
   void SaveProejct();
   void OpenProject();
 protected:
  virtual void New();
  virtual void Save();
  virtual void Open();
};
The virtual functions are reimplemented in the derived classes cause only the specific program knows how ( which objects to save to disk ) to actually save the project.
Also part of saving new or opening a project is showing the SaveAs/Open dialog from which the user will select where to save/open the project. For example, the NewProject() is implemented in terms of the New method:
void Project::NewProject()
{
  1. // Show dialog for whether to save existing project
  2. // check whether the project was already saved
  3. // if yes, only overwrite the existing project
  4. // if no, show SaveAs Dialog
  5. // ...
  6. this->New();
}  
Line 1 to 5 is code that all of my programs need, i.e the flow and order in which the dialogs are created and checks are performed is the same.
I was thinking whether the actual code that creates the dialogs should be placed in the Project::New and Project::Open methods. After some thinking I decide that it is not good solution cause the Project class is model class, and model class should not create GUI. So, I was thinking maybe the best place to write the code from line 1 to line 5 , is in the Save/Open buttons event handlers of the specific program. But that means that I will have to duplicate it for each program .
So the question is how should I separate the creating of dialogs which will be the same for all of my programs from the actual saving/opening of the projects in way that do not require duplicating of code ?