Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 406747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:31:36+00:00 2026-05-12T17:31:36+00:00

I am trying to determine the best design pattern to use for a business

  • 0

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:

  1. 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.

  2. 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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:31:36+00:00Added an answer on May 12, 2026 at 5:31 pm

    Chain of responsability

    Each processing object contains a set of logic that describes the types of command objects that it can handle, and how to pass off those that it cannot to the next processing object in the chain

    So you define and abstract SearchSystem ( or SystemSearch ) and add subclasses like this:

    class SearchSystem
    {
        //link to the next in the chain 
        SearchSystem next;
    
        // Basic search, If cannot handle forward to the next.
        public Result search( Criteria c ) 
        {
            Result r = doSearch( c );
    
            if( r != null ) 
            {
                return r;
            }
    
            return next.search( c );
        }
        // subclass specific system search
        abstract Result doSearch( Criteria c );
    }
    
    class SearchSystemOne: SearchSystem 
    {
        Result doSearch( Criteria c )
        {
            // do some system 1 speficif stuff 
            // and return either and instance or null
        }
    }
    class SearchSystemTwo: SearchSystem 
    {
        Result doSearch( Criteria c )
        {
            // do some system 2 speficif stuff 
            // and return either and instance or null
        }
    }
    .... etc etc. 
    // End of the chain
    class SearchSystemOver: SearchSystem 
    {
        public Result search( Criteria c ) 
        {
            throw new ApplicationException("Criteria not foud", c );
        }
        Result doSearch( Criteria c )
        {
           // didn't we throw exception already?
        }
    }
    

    Instantiate

    SearchSystem one = new SearchSystemOne();
    SearchSystem two = new SearchSystemTwo();
    SearchSystem three = new SearchSystemThree();
    SearchSystem four = new SearchSystemFour();
    SearchSystem over = new SearchSystemOver();
    

    And build the chain

    one.next = two;
    two.next = three;
    three.next = four;
    four.next = over;
    

    And finally search it.

    SearchSystem searcher = one;
    
    searcher.search( Criteria.addName("Oscar").addLastName("Reyes"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to determine the best approach for building a WCF Service, and the
I'm trying to determine how to best design a storage facility for fast searching
I'm trying to determine the best table design for a follow/unfollow user feature, similar
I am trying to figure the best logic to determine if the user of
I'm trying to find a design pattern or a best practice, or some other
I'm trying to determine the best way to organize our Maven / Spring web
I am trying to determine the best way to create a treeview list in
I'm trying to determine the best way of deploying new versions of an established
Short version: I'm trying to determine the best way to track what the user
I am trying to determine which implementation of the data structure would be best

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.