On Mon, 30 May 2011 11:22:39 +0200, Daniel Gibson <metalcae...@gmail.com> wrote:

How is
auto logCrash = new Log(new EmailLogEngine(MailProto.SMTP,
"smtp.myserver.com"));
better than
auto logCrash = new Log(new SMPTLogEngine("smtp.myserver.com")); ?

Well, my answer was too fast. Look at this:


enum MailProto { SMTP, IMAP, MSEXCH }

class EmailLogEngine : LogEngine
{
public this(string host, string user, string psw, MailProto type = MailProto.SMTP, int port = 0)// most common defaults
    {
        if (port == 0)
            switch(type) {
            case SMTP: port = 25; break;
            }

        // initialize mail server structures
    }
}

In this case

auto logCrash = new Log(new EmailLogEngine("smtp.myserver.com", `user`, `psw`));

is enough for most usages. Even better:

auto logCrash = new Log(new EmailLogEngine(Settings.MailHost, Settings.MailUser, Settings.MailUserPsw, Settings.MailType));

This line even doesn't require recompilation, using params from settings. What you'll do with your SMTPLogEngine if tomorrow we switch to MS Exchange? Jumping around with find/replace? And you don't catch the main point: lower you go in implementation - harder you use it again, so 'be generic' is a good advice here.

Reply via email to