I am going through training at my new job to use good object-oriented design with a 3-tier programming style. My supervisor says I have a design problem with my code:
class Program
{
public static void Main()
{
UserInputValidator Validater = new UserInputValidator();
int logSelected = -2;
Console.Write("\nFilepath: ");
string filePath = Console.ReadLine();
while (logSelected != -1)
{
Console.WriteLine("\n" + "SELECT AN OPTION MENU");
Console.WriteLine("-----------------------");
Console.Write("\n" +
/* Display option menu here with several options */
"9 ) Exit\n\n");
Console.WriteLine("-----------------------");
logSelected = Convert.ToInt32(Console.ReadLine());
Validater.ValidateOptionsMenu(logSelected, filePath);
}
}
public void DisplayMessage(string message)
{
Console.WriteLine(message);
}
}
Validator.ValidateOptionsMenu() handles the logic for starting a process depending on the option that was selected.
This is a 3-layer application with Presentation, Business, and Data Access layer. Program is in the Presentation layer, and other layers use code similar to the following to display a message:
Program program = new Program();
program.DisplayMessage(message);
I need to understand why this is bad practice - my supervisor says the class Program only starts the application, like App class in WPF. It has to have only 1 responsibility. The interaction with user (my option menu) is delegated to another class. I am having a hard time understanding my supervisor, and I'm not sure how to fix it. Can anyone help me understand?
logSelected
is -1, when it's the value 9 that should end the program. But that might just be a typo. – cHao Apr 29 '11 at 15:58Validator
should validate. It shouldn't be causing anything to happen; that's the job of whatever uses the data after the validator's made sure it's correct. It certainly shouldn't be causing magical exits from the app. – cHao Apr 29 '11 at 16:37UserInputValidator Validater = new UserInputValidator();
- you typed "validator" correctly twice but still managed to spell the variable name incorrectly? – Ant Apr 30 '11 at 7:39