I'm really intrigued by OOP, I feel that I can help most people with OOP questions reasonably well, but I still have a lot to learn and there's something that bothers me. What is the best way to write the program's main() if I want to create a truly OOP C++ program?
My OOP programs tend to be something I would call "Procedural using Objects". They're not really procedural, but they're not really OOP either. For example, here's the main() from a program that I'm currently working on:
int main() {
cout << "Lakewood ITA Administration Console Version 2.0\nCopyright, 2010 Lakewood Construction" << endl;
while(true) { //begin application loop
string userInput;
cout << "What would you like to do?\n";
cout << "\t1. Manage supervisors\n";
cout << "\t2. Manage projects\n";
cout << "\t0. Quit" << endl;
cout << "Choice: ";
getline(cin, userInput, '\n');
char menuChoice = userInput.at(0);
if (menuChoice == '1') {
if (!manageSupervisors())
cout << "Error in supervisor management system.\nPlease inform an administrator." << endl;
} else if (menuChoice == '2') {
if (!manageProjects())
cout << "Error in Project management system.\nPlease inform an administrator." << endl;
} else if (menuChoice == '0')
break;
else {
cout << "Invalid menu choice, please select again." << endl;
}
} //end application loop
cout << "Thank you for using ITA. Good bye!" << endl;
cin.get();
return 0;
}
As you can see, this is all procedural. You can't see it here, but I don't start getting into any sort of OOP until manageSupervisors() or manageProjects() is called. Once they start, I create vectors of either Supervisor or Project objects and begin manipulating both the overall vectors and the individual objects.
The main thrust of my question is this:
In C++, is there a better (more appropriate) way to write an OOP program's main(). How can I best create a "true" OOP program in C++? Assuming I convert the sub-systems (project management and supervisor management) to polymorphic classes, would something like this be better?:
int main() {
cout << "Lakewood ITA Administration Console Version 2.0\nCopyright, 2010 Lakewood Construction" << endl;
ITA::System *subSystem = 0; //create a pointer to an ITA System
while(true) { //begin application loop
string userInput;
cout << "What would you like to do?\n";
cout << "\t1. Manage supervisors\n";
cout << "\t2. Manage projects\n";
cout << "\t0. Quit" << endl;
cout << "Choice: ";
getline(cin, userInput, '\n');
char menuChoice = userInput.at(0);
if (menuChoice == '1')
subSystem = new supervisorManager; //initialize the supervisor subsystem
else if (menuChoice == '2')
subSystem = new projectManager; //initialize the project subsystem
else if (menuChoice == '0')
break;
else
cout << "Invalid menu choice, please select again." << endl;
subSystem.execute();
delete subSystem; //de-allocate the pointer
} //end application loop
cout << "Thank you for using ITA. Good bye!" << endl;
cin.get();
return 0;
}
Any advice at all would be appreciated.