Skip to content

Conversation

@Max-Browckin
Copy link
Owner

No description provided.

Copy link

@avfyodorov avfyodorov left a 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 {

Choose a reason for hiding this comment

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

  1. Можно было бы провести рефакторинг, в базовый класс (BaseHttpHandler) перенести обработчик и там же методы-заглушки, а в классах наследниках переопределять только эти методы (processGet, processPost….), если они нужны. Такое решение лучше соответствует принципам OOP.
    Такой подход уменьшает количество повторяющегося кода и позволяет проще вносить в него изменения.

На усмотрение.

Copy link
Owner Author

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;

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);
}
}

Choose a reason for hiding this comment

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

  1. Далее в каждом из наследников мы будем переопределять только нужные для этого наследника методы 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 {

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 {
..................

.---------------------

Аналогично определяются классы-наследники и для эпиков, подзадач, истории.

Copy link

@avfyodorov avfyodorov left a comment

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.

3 participants