Design patterns

G

Guest

I am quite new to design patterns and would like advice and help on the following problem I am having

I am writing a program to send emails to customers for a company. There are different types of emails that have common elements such as order and payment details. Other elements are different such as the first paragraph. EG “Thank you for your recent order of the followingâ€, “Thank you for your recent return of the followingâ€, “Thank you for your recent return reorder of the followingâ€. The email may be sent in HTML format or text format with future formats being a possibility. My problem is that if use one class to build a whole text letter, then the logic for determining email content would have to be copied to the class to create html letters as well which is not a good idea as changes in one would require changes in the other. Html letters have different formatting to take advantage features of HTML however the textual content is the same. The import to the text builder is a orders class which contains all necessary details of the order required for the letter. In future I would also be providing printed copies of the letters with barcoding so that is another future format.

If someone has any ideas on a class hierarchy I would be eternally gratefu

Regard
Danie
 
S

Steve Lutz

Hi Daniel,

I had a similar situation, and needed to create custom emails automatically.
The design I came up with is as follows:

We would know the format the customer was to get email in, such as HTML or
Plain Text. We also had another format called "AOL" which just contained the
HTML that AOL's email reader could handle.

We created mail "templates". In these templates, we would place fields for
where the system was to provide actual content. We called it the
"Notification Markup language" - mainly because we had MANY different emails
going out, and they were for account notifications.. Get it?

Here's a sample:

Hello <<CUSTOMER.FIRST NAME>>:

You account is past due.. blah blah blah.. You're current balance is
<<CUSTOMER.BALANCE>>. You have until <<DUEDATE>> to pay.

or

You ordered the following items:
<<LOOP ORDERITEMS>>
Item <<ITEM.NUMBER>> - <<ITEM.DESCRIPTION>> - <<ITEM.PRICE>>
<<END LOOP ORDERITEMS>>
Total Order: <<ORDER.TOTAL>>

I wrote an object class that would take a customer ID and the template ID as
input, and output the text of the email. Which I would then send to another
program for actual delivery. The "fill in the blank" type fields were easy.
The Loop required a lot of effort, and we only implemented single loops (no
nesting or anything fancy).

The design worked well (actually, it's still working :) , as it allowed for
quick and easy changes to the actual email templates, or additions, without
the need to recompile. It was so simple that our marketing department could
create the templates, and all I needed to do was test them once to see if
they worked.

Hope that helps.

Steve






Daniel said:
I am quite new to design patterns and would like advice and help on the following problem I am having.

I am writing a program to send emails to customers for a company. There
are different types of emails that have common elements such as order and
payment details. Other elements are different such as the first paragraph.
EG "Thank you for your recent order of the following", "Thank you for your
recent return of the following", "Thank you for your recent return reorder
of the following". The email may be sent in HTML format or text format with
future formats being a possibility. My problem is that if use one class to
build a whole text letter, then the logic for determining email content
would have to be copied to the class to create html letters as well which is
not a good idea as changes in one would require changes in the other. Html
letters have different formatting to take advantage features of HTML however
the textual content is the same. The import to the text builder is a orders
class which contains all necessary details of the order required for the
letter. In future I would also be providing printed copies of the letters
with barcoding so that is another future format.
 
G

Guest

Thanks for your reply and help. i did try a solution with the use of templates using xslt transformations. It was however hard to implement if statements conditional logic with loops. Perhaps i was trying to do too much with it and should revisit it. I was also worried about the number of templates i would have to create with only minor parts that varied. For example the header might be "thank you for your return of the following" or "thank you for your recent order of the following", so i would have to write different templates for each one, even though only the header might be different.

I will revisit it i think and see if i can make it work as you have..

Kindest regards
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top