Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What design-pattern I should use in my notification system?

Which design-pattern I should use in this case:

  • I have a rest API notification system.
  • I can notify by Email
  • notify by push;
  • notify by WhatsApp.
  • And I want to implement more technologies, and I do not want to modify the core, I want to add only modules to the system. For example, adding Telegram Messages, Twitter messages, or another email provider.

    Any recommendation?

    like image 215
    José Alonso Avatar asked Feb 22 '18 05:02

    José Alonso


    3 Answers

    According to your problem statement, two different types of design patterns will be involved:

    1) Strategy Pattern: It will define the notification strategy based on the contexts like email, push, whatsapp, etc.

    3) Observer Pattern: It will perform the publisher and subscribers operation will the behavior of loose coupling. It will automatically notify to subcriber.

    You can also integrate RabbitMq somewhere for queuing and on time pushing messages.

    like image 173
    Gul Ershad Avatar answered Sep 25 '22 12:09

    Gul Ershad


    The case you explained is like strategy design pattern . You can use strategy design pattern and have an interface and a class for your each system that implement your interface. These are links that can help you :

    tutsplus design ptterns

    designpatternsphp

    like image 40
    Mohsen Jalalian Avatar answered Sep 24 '22 12:09

    Mohsen Jalalian


    For a notification system I would suggest you using the Observer pattern. The message you receive should be inside your Subject. Subject should allow any number of Observers to attach. When a message is received, the subject should notify all the observers. Then Observers can read the state/message from the subject and act upon it. I am not pretty much clear about your usecase. But this would do the job.

    like image 28
    Ravindra Ranwala Avatar answered Sep 22 '22 12:09

    Ravindra Ranwala