-
Notifications
You must be signed in to change notification settings - Fork 0
Sprint 9 solution http api #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
avfyodorov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добрый день, Максим!
Отличная работа, есть всего одно уточнение, но и оно на Ваше усмотрение.
| } | ||
|
|
||
| @Override | ||
| public void handle(HttpExchange exchange) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Можно было бы провести рефакторинг, в базовый класс (BaseHttpHandler) перенести обработчик и там же методы-заглушки, а в классах наследниках переопределять только эти методы (processGet, processPost….), если они нужны. Такое решение лучше соответствует принципам OOP.
Такой подход уменьшает количество повторяющегося кода и позволяет проще вносить в него изменения.
На усмотрение.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я их изучил, но пока решил не вносить изменения, так как они не критичны для проекта.
| .create(); | ||
|
|
||
| @Override | ||
| public abstract void handle(HttpExchange exchange) throws IOException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Далее в каждом из наследников мы будем переопределять только нужные для этого наследника методы 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А для отсортированного по времени списка достаточно будет переопределить всего один метод:
public class PrioritizedHandler extends BaseHandler {
@Override
protected void processGet(HttpExchange exchange, String path) throws IOException {
...................---------------------
Аналогично определяются классы-наследники и для эпиков, подзадач, истории.
avfyodorov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добрый день, Максим!
Замечаний нет.
Работа принята.
No description provided.