Skip to content

console kotlin#1

Open
Chozk wants to merge 4 commits intomainfrom
dev
Open

console kotlin#1
Chozk wants to merge 4 commits intomainfrom
dev

Conversation

@Chozk
Copy link
Copy Markdown
Owner

@Chozk Chozk commented Jul 23, 2024

No description provided.

Comment thread src/main/kotlin/MenuArchive.kt Outdated
archives.forEachIndexed { index, archive -> println("${index + 1}. ${archive.name}") }
}
println("0. Создать архив")
println("выход. Выйти")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Лучше выход тоже обозначить цифрой, а не строкой "выход". Так пользователю программы удобнее будет с ней работать

Comment thread src/main/kotlin/MenuNoteCreate.kt Outdated
Comment on lines +22 to +23
override fun handlePick(pick: String) {
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Если не всем наследникам класса Menu нужно переопределять этот метод, можно его сделать open, а не abstract. Тогда можно будет удалить пустые реализации в наследниках.

Вот так будет в Menu:

protected open fun handlePick(pick: String) = Unit

Unit в данном случае будет аналогом { }

Comment thread src/main/kotlin/data/Archive.kt Outdated

data class Archive(
val name: String,
val notes: MutableList<Note> = mutableListOf())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 В Kotlin принят немного другой стиль форматирования кода, быстро отформатировать код в Android Studio можно следующей комбинацией клавиш: в Windows Ctrl + Alt + L , в MacOs ⌘ + ⌥ + L

Comment thread src/main/kotlin/data/Note.kt Outdated

data class Note(
val title: String,
val content: String)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 В Kotlin принят немного другой стиль форматирования кода, быстро отформатировать код в Android Studio можно следующей комбинацией клавиш: в Windows Ctrl + Alt + L , в MacOs ⌘ + ⌥ + L

Comment thread src/main/kotlin/MenuNote.kt Outdated
import data.Note

class MenuNote(private val archive: Archive) : Menu<Note>(archive.notes) {
private val notes = items
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Кажется, нет плюсов от параметризации Menu и передачи айтемов в Menu, если ты их в Menu никак не используешь.
Если все-таки хочешь оставить параметризацию, то нужно удалить private val notes = items тк по сути создается вторая коллекция, хотя ты можешь просто обращаться не к notes, а к items

}
}

fun readLine(prompt: String): String {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 По кодстайлу лучше сначала в файле все публичные функции, а ниже приватные

Comment thread src/main/kotlin/MenuNote.kt Outdated
Comment on lines +5 to +10
private val menuManager = MenuManager()

init {
menuManager.menuAddItem("Создать заметку") { MenuNoteCreate(archive.notes).show() }
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Вот тут нет пользы от menuManager, тк вызывается menuAddItem, но не вызывается menuShow, в котором используется результат работы menuAddItem.

В результате нельзя создать заметку(

Снимок экрана 2024-07-25 в 21 56 01

Comment thread src/main/kotlin/MenuArchive.kt Outdated
Comment on lines +11 to +18
override fun show() {
while (true) {
menuDisplay()
val pick = getUserPick()
if (pick == "0") break
handlePick(pick)
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 В этом методе точно такой же код, что и в родительском классе Menu, поэтому его можно удалить отсюда. show отработает, даже если будет только в родительском классе

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