locked
best design to add confirmation email functionality RRS feed

  • Question

  • User175570332 posted

    I have a web application that needs to send out email confirmations when a user subscribes to its service. I know how to use the email api, but I am wondering what the best way to integrate this into my project is.  The confirmation emails will only get sent from one page, but it doesnt seem right to just write the couple lines onto that page. I would like to abstract it out to an external class. Below are some of the consideratiosn I've made so far.

    Create a new class for email. I called it Email. should it maybe be called SendEmail? I can't decide a good name for this.

    Create a static method in the class that can be used anywhere on my site. -- Seems ok, but I feel like I rely on static methods far too often for things like this. Is there a better way?

    Create a non static method taking in the parameters to the email api and put everything together and send it off -- Why go through the work of constructing a separate obj.

    Anyway, if you guys have ideas for me, lets here em.

    Thanks!

    Thursday, June 9, 2011 12:49 PM

Answers

  • User-389939489 posted

    I would leave the couple of lines of code into the page.

    The day you have to send emails from two or more pages, you will have enough requirements to drive the abstraction and development of a static class.

    The day you have to do something even more complex, you will have enough requirements to drive the abstraction and development of a class and its life-cycle.

    IMO, the relevant best practice here is the keep it simple (incremental).

    -LV

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 9, 2011 3:53 PM

All replies

  • User-389939489 posted

    I would leave the couple of lines of code into the page.

    The day you have to send emails from two or more pages, you will have enough requirements to drive the abstraction and development of a static class.

    The day you have to do something even more complex, you will have enough requirements to drive the abstraction and development of a class and its life-cycle.

    IMO, the relevant best practice here is the keep it simple (incremental).

    -LV

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 9, 2011 3:53 PM
  • User175570332 posted

    Thanks! Sounds good to me.  I was really debating which way I should do it, but this philosophy makes sense.

    Thursday, June 9, 2011 5:28 PM