상속: ICommandParser
        public static void Main()
        {
            var commandsFactory = new PhonebookCommandsFactory();
            IPhonebookRepository repository = new PhonebookRepositoryWithDictionary();
            var parser = new CommandParser();

            // TODO: To extract Print class
            StringBuilder input = new StringBuilder();

            while (true)
            {
                string currentLine = Console.ReadLine();
                currentLine = currentLine.Trim();
                if (currentLine == "End" || currentLine == null)
                {
                    break;
                }

                var commandInfo = parser.Parse(currentLine);

                IPhonebookCommand command = commandsFactory.GetCommand(commandInfo.CommandString);
                command.Execute(commandInfo.Arguments, repository);
            }

            Console.Write(input);
        }
예제 #2
0
        internal static void Main()
        {
            IPhonebookRepository data = new PhonebookRepositoryWithDictionary();
            IPrinter printer = new StringBuilderPrinter();
            IPhoneNumberSanitizer sanitizer = new PhoneNumberSanitizer();
            ICommandFactory commandFactory = new CommandFactoryWithLazyLoading(data, printer, sanitizer);
            ICommandParser commandParser = new CommandParser();
            while (true)
            {
                string userInput = Console.ReadLine();
                if (userInput == "End" || userInput == null)
                {
                    break;
                }

                var commandInfo = commandParser.Parse(userInput);
                IPhonebookCommand command = commandFactory.CreateCommand(commandInfo.CommandName, commandInfo.Arguments.Count());
                command.Execute(commandInfo.Arguments.ToArray());
            }

            printer.Accept(new ConsolePrinterVisitorWithNewLine());
        }