public static MessageHandler getMessageHandler(Message message, ChatView chatView, ChatModel chatModel) throws UnknownMessageException {

        if (message instanceof ServerErrorMessage) {
            if (message instanceof FatalErrorMessage) {
                return new ServerErrorMessageHandler(message, chatView, chatModel);
            } else {
                return new RuntimeServerErrorMessageHandler(message, chatView, chatModel);
            }
        }

        if (message instanceof ChatMessage) {
            if (message instanceof ConnectEventMessage) {
                return new ConnectEventMessageHandler(message, chatView, chatModel);
            } else {
                if (message instanceof DisconnectEventMessage) {
                    return new DisconnectEventMessageHandler(message, chatView, chatModel);
                } else {
                    return new ChatMessageHandler(message, chatView, chatModel);
                }
            }
        }

        if (message instanceof ServerInfoMessage) {
            if (message instanceof ConnectionInterruptInfoMessage) {
                return new ServerInfoMessageHandler(message, chatView, chatModel);
            } else {
                return new RuntimeServerInfoMessageHandler(message, chatView, chatModel);
            }
        }

        if (message instanceof UsersOnlineServerMessage) {
            return new UsersOnlineServerMessageHandler(message, chatView, chatModel);
        }

        if (message instanceof ChatHistoryMessage) {
            return new ChatHistoryMessageHandler(message, chatView, chatModel);
        }

        throw new UnknownMessageException("Unknown message");
    }