Using the factory pattern to create different emails based on input parameters

Using the factory pattern to create different emails based on input parameters

I wrote a small service that takes an MQ message as input, and based on the contents of the message creates and sends an email. The different types of incoming MQ messages require different types of emails to be created, so I needed a maintainable way to create different emails.

For my use case, I found that the factory pattern was a good fit. Consider this code:

My business logic code that uses this code then get to be as simple as this:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: