Open
Conversation
added 30 commits
December 4, 2024 18:15
avfyodorov
reviewed
Mar 2, 2025
avfyodorov
left a comment
There was a problem hiding this comment.
Добрый день, Максим!
Отличная работа, есть всего одно уточнение, но и оно на Ваше усмотрение.
| } | ||
|
|
||
| @Override | ||
| public void handle(HttpExchange exchange) throws IOException { |
There was a problem hiding this comment.
- Можно было бы провести рефакторинг, в базовый класс (BaseHttpHandler) перенести обработчик и там же методы-заглушки, а в классах наследниках переопределять только эти методы (processGet, processPost….), если они нужны. Такое решение лучше соответствует принципам OOP.
Такой подход уменьшает количество повторяющегося кода и позволяет проще вносить в него изменения.
На усмотрение.
Owner
Author
There was a problem hiding this comment.
Я их изучил, но пока решил не вносить изменения, так как они не критичны для проекта.
| .create(); | ||
|
|
||
| @Override | ||
| public abstract void handle(HttpExchange exchange) throws IOException; |
There was a problem hiding this comment.
public class BaseHandler implements HttpHandler {
......................
public void handle(HttpExchange exchange) throws IOException {
String method = exchange.getRequestMethod();
switch (method) {
case "GET":
processGet(exchange);
break;
case "POST":
processPost(exchange);
break;
case "DELETE":
processDelete(exchange);
break;
default:
writeToUser(exchange, "Данный метод не предусмотрен");
}
protected void processGet(....) {
sendMethodNotAllowed(...);
}
protected void processPost(....) {
sendMethodNotAllowed(...);
}
.......................
И здесь же общие методы для классов-наследников. | sendInternalError(exchange); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
- Далее в каждом из наследников мы будем переопределять только нужные для этого наследника методы processGet, processPost и т.д. и реализовывать в них нужную нам логику)
Для задач приблизительно так:
public class TasksHandler extends BaseHandler {
......................
public TasksHandler(........................
@Override
protected void processGet(HttpExchange exchange, String path) throws IOException {
.........................
@Override
protected void processPost(HttpExchange exchange) throws IOException {
...............
@Override
protected void processDelete(HttpExchange exchange, String path) throws IOException {
.......................| } | ||
|
|
||
| @Override | ||
| public void handle(HttpExchange exchange) throws IOException { |
There was a problem hiding this comment.
А для отсортированного по времени списка достаточно будет переопределить всего один метод:
public class PrioritizedHandler extends BaseHandler {
@Override
protected void processGet(HttpExchange exchange, String path) throws IOException {
...................---------------------
Аналогично определяются классы-наследники и для эпиков, подзадач, истории.
avfyodorov
reviewed
Mar 4, 2025
avfyodorov
left a comment
There was a problem hiding this comment.
Добрый день, Максим!
Замечаний нет.
Работа принята.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.