Skip to content

Минка - 2 tasks complete.#26

Open
AlexanderMNK wants to merge 21 commits intodemologin:mainfrom
AlexanderMNK:main
Open

Минка - 2 tasks complete.#26
AlexanderMNK wants to merge 21 commits intodemologin:mainfrom
AlexanderMNK:main

Conversation

@AlexanderMNK
Copy link

Большую часть времени разбирался с Гитом, как совершенно новой для меня технологией, с которой я ни разу не сталкивался. Позже хочу заново переработать весь код (для себя) на новом уровне, досконально изучив и проработав более совершенные подходы к построению архитектуры программы.

Copy link

@Khmelov Khmelov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Неплохо написанное приложение, если бы не небольшой объем поставил бы максимальную оценку. В целом при двух задачах многие менторы ставят оценку C, но за счёт аккуратно написанных классов я решил поставить оценку B

while (true) {
int choice = menu.showMainMenu(scanner);

if (choice == 1) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Числам можно дать какие-нибудь имена в виде констант, это должно повысить читаемость кода

} catch (RuntimeException | IOException e) {
System.out.println("Ошибка " + e.getMessage());
}
} else if (choice == 3) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

С учётом того что команд всего три то построения логики на основе разветвлений выглядит приемлемо, однако в реальных приложениях команд сотни и более, поэтому полезно сразу формировать их хранения в виде карты. Такое решение более легко масштабируется


public class CryptoProcessor {
public void encrypt(String inputFile, String outputFile, int key) throws IOException {
CryptoAction action = new Encrypt();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот объект никогда не будет изменяться, поэтому лучше его вынести в поле и создавать только однажды в момент создания криптопроцессора

}

public void decrypt(String inputFile, String outputFile, int key) throws IOException {
CryptoAction action = new Decrypt();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

То же самое


public class Menu {
public int showMainMenu(Scanner scanner) {
System.out.println("-".repeat(70) +
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут наверное пригодились тройные кавычки


import java.util.Scanner;

public class ConsoleRunner {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

То что приложение небольшое совсем не означает что ему не нужны пакеты, в реальных приложениях классов всё равно очень много, и поэтому привычка размещать все по пакетам очень хорошая

DefaultFilePathBuilder filePathBuilder = new DefaultFilePathBuilder();
InputParamsReader inputParamsReader = new InputParamsReader(scanner, filePathBuilder);
CryptoProcessor cryptoProcessor = new CryptoProcessor();
CryptoApp cryptoApp = new CryptoApp(cryptoProcessor, menu, inputParamsReader, scanner);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут всё верно


public class Encrypt extends CryptoAction {
@Override
protected char transform(char c, int key) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кот в классах шифрования и дешифрования очень похож и по сути может быть вынесен в абстракцию

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants