Is there a good design pattern for this?

I want to create a messaging class.

The class will be passed:

the type of message (eg. signup, signup confirmation, password reminder etc) the client's id The class needs to then look up the client's messaging preferences in the db (whether they want communication by email, sms or both)

Then depending on the client's preference it will format the message for the medium (short version for sms, long form for email) and send it through our mail or sms provider's API.

Because the fact that we want to be able to change out email and sms providers if need be I wondered if the Command Pattern would be a good choice.


I would create an interface with the ability to return a short or long message. Then instantiate a class matching the type of message (signup) and send it to the correct transmission class (SMS), allowing the transmission class to interrogate the message for whatever information it needs (the short version of the message).

I am not sure off hand what design pattern that would be, but it keeps the implementation details as close as possible to their responsible parties I believe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.