views:

67

answers:

2

So there is an internal email application, that has different installations in the company (various departments).

When an email comes into the system, I need to perform a lookup based on the email address. Each lookup will be different, depending on the department's installation.

e.g. When an email arrives in the accounting department, lookups on the email will be specific to a particular database.

When an email arrives in the sales department, lookups will be specific to our customer database.

Since each user lookup database is different, I need to design a very flexible user lookup mechanism so that department specific code can be easily managed.

What is the best way to design this type of functionality?

+2  A: 

Create an interface like the following:

interface ILookUpEmail
{
    Email GetEmail(string email);
}

You can have many classes which implement this interface with their own logic. This will decouple your code, allowing you to set which LookUpEmail type you're using, and make for easy testing of each implementation and controller for the email lookup. You would be implementing a State Pattern and also following the Open/Closed principle on your method for looking up the email. Another option is to use a Factory Pattern, having a class which returns the proper EmailLookup class.

Yuriy Faktorovich
A: 

There are multiple ways to achieve the desired functionality. You may use strategy pattern combined with Factory Pattern. Factory will create you proper algorithm (strategy) given some run-time info (department ID for instance). These algorithms may all implement ILookUpEmail interface suggested by Yuriy Faktorovich, so you program does not really need to know how these algorithms work (they belong to business rules domain and ideally should not be coupled with implementation of you e-mail application, as rules may change often, and you should not need to recompile entire application because of that).

BostonLogan