jeudi 23 août 2018

Choosing the correct design pattern

I'm writing an api in the form of a .net Standard library. In this library, I need to provide the caller a class which will allow me to send and receive messages from a message queue. The underlying queuing system could be anything, such as ServiceBus, NATS or RabbitMQ and therefor should be interchangeable by the caller.

Something like this:

public class QueueWrapper: IQueue {

    private QueueClient _q;

    public QueueWrapper(QueueClient q) {
       _q = q;
    }

    public void Send() { 
        q.send();
    }

    public string Receive() { 
        return q.receive();
    }
}

Called by:

IQueue msgQueue = new QueueWrapper(new RabbitMQClient());

I think the Adapter Pattern is the correct Design Pattern to choose, but wanted to get advice - does this seem like the correct pattern in this scenario? Would you recommend others?

A similar scenario would be having an emailer class that sends mails and allowing different mail providers to be switched.

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire