lundi 9 mai 2022

Does the Observer Design Pattern Work For Food Delivery Status Updates?

I've recently been learning about the Observer design pattern and understand canonical examples like newspapers notifying their subscribers like so:

public class NewsPaper implements Publisher{
    List<Subscriber> subscribers;

    @Override
    public void register(Subscriber s) {
        this.subscribers.add(s);
    }

    @Override
    public void unregister(Subscriber s) {
        this.subscribers.remove(s);
    }

    @Override
    public void update(String type) {
        this.subscribers.forEach(subscriber -> subscriber.update()));
    }
}

I was thinking about how something like this would translate to a food delivery notification service where each delivery needs to be notified separately. For example the delivery status would send updates when the order is "on the way", "arriving", ect. Is there a way to apply the observer problem (or another design pattern) to notification services like food delivery?

A map could be used to map each delivery order to the subscribers, but this seemed inefficient since it most likely would be a one -> one relationship.

Aucun commentaire:

Enregistrer un commentaire