Reputation: 1451
I want to design a wrapper to talk to Message Queue(s)f. The implementation of the wrapper should be generic enough so that client of the library doesn't have to make any code changes if they want to switch from one MQ provider (for example RabbitMQ) to another MQ Service (say Amazon SQS).
What Design Pattern would you recommend for the library and why?
Upvotes: 1
Views: 1848
Reputation: 5649
You are looking for the Adapter design pattern.
Let's say you have two queueing technologies: Q1 and Q2. Each of them provides different methods to interact with them. The class design looks like the following:
IQueue
, with generic methods. For e.g., getMessage(), postMessage() and deleteMessage().IQueue
. Similarly, for Q2.IQueue
. Then, switching from Q1 to Q2 simply involves replacing one adapter class with another.Upvotes: 4