Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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