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.
Thanks for any feedback.
I’m not sure you need a pattern for this. It sounds more like just simple inheritance with an abstract method for the actual message sending.
Consider dividing the tasks better. Perhaps make it the responsibility of the user ID to look up the preferences, or just code a third class for it.
If you want to use a design pattern, then Builder might apply to constructing the actual messages. This depends on whether you need different formatting for the different message delivery methods.