Hello all,
I am trying to determine the best design pattern to use for a business key validation web service. The basic logic flow is coded below. The program will take a parameter and use a field to help determine the path to take in searching multiple systems where this business key can be found. System1 is searched first, if not found, search System2 and System3. The System1 search logic depends on a field in the parameter passed into the original validation method.
I am not exactly sure which design pattern to use. It looks like Command, Chain of Responsibility, Template Method all could be used here.
With my implementations below, I see the following problems:
Each SearchSystemX method needs to know to return null if the business key is not found so that the "control" method will continue to search other systems.
Each SearchSystemX must know how to populate the business object, currently just implemented by a simple primitive string, but that is for example only.
Please let me know your thoughts.
public string Validate (string parms) {
string returnValue = null;
returnValue = SearchSystem1(parms);
if (returnValue == null) {
returnValue = SearchSystem2(parms);
if (returnValue != null) {
returnValue = SearchSystem3(parms);
}
else if (returnValue == null) {
if (parms == "Criteria1") {
returnValue = SearchSystem4(parms);
if (returnValue == null) {
throw new ApplicationException("ID Invalid");
}
}
else if (parms == "Criteria2") {
throw new ApplicationException("ID Invalid");
}
}
}
return returnValue;
private string SearchSystem1 (string parms) {
string returnValue = null;
if (parms == "Criteria1") {
returnValue = SearchSystem1UsingColumn1(parms);
}
else if (parms == "Criteria2") {
returnValue = SearchSystem1UsingColumn2(parms);
if (returnValue == null) {
returnValue = SearchSystem1UsingColumn4(parms);
}
}
if (returnValue != null) {
returnValue = FetchXYCoordinate(parms);
}
return returnValue;
}
Thanks!