E
E
Evgeniy Rybalko2020-05-13 16:55:08
Java
Evgeniy Rybalko, 2020-05-13 16:55:08

What design pattern to apply?

Good afternoon
Please tell me which design pattern to apply.
There is an application that processes notifications from different monitoring systems and stores them in a unified form (for example, an event identifier, system type, trigger that caused the event and event status) - already implemented at the moment.
From this application it is necessary to develop a mechanism for approving/acknowledging notifications.
What is at the moment:

  • Common interface for all "connectors"
    public interface Connector {
        void validate(String login, String password);
        void validate(String token);
        void authenticate(String login, String password);
        void authenticate(String token);
        void acknowledge(String alertId);
        List<String> getRules();
    }

  • Service for storing settings and information about a third-party system (system type, login, password, address)

How I'm going to decide for now:
All "connectors" must implement the Connector interface (for example, ZabbixConnector).
When an alert is acknowledged in my application, we get its id, system ID, and data for authorization in this system. by system id in enum we find the class that should handle the notification
public enum ConnectorEnum {
ZABBIX(0, "Zabbix", ZabbixConnector.class)
}

In my very humble experience, I understand that there is something wrong with this approach. But I don't understand what I need to fix...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Kalachyan, 2020-05-15
@Bringoff

Well, the way of thinking is generally normal, but it is not clear why Enum. You need something in the style of dispatching by key, but how to do it in Java, you have to think about it.

G
gbman, 2020-05-21
@gbman

Have you looked at https://refactoring.guru/en/design-patterns/observer ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question