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 1114895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:04:31+00:00 2026-05-17T03:04:31+00:00

My code is something like this : if(country == china) { getCNData(); } else

  • 0

My code is something like this :

if(country == china)
{
getCNData();

}

else {
getDefaultDataForallCountries();

}

Now I need to add similar logic as CN for some other country say US . The option available to me is to add one more country check in if condition and make it like

if(country ==china && country==US){
getCNandUSData();

}

else {
getDefaultDataForallCountries();


}.

1) I am somehow not comfortable to go for this solution as this is not generic . What if tomorrow I need to have same CN logic applied to another country say france . Can you please suggest me how can I make my code better and more generic.

2) Also I am not comfortable with the naming conventions. If say I go with my approach of adding US in If condition , Should I refactor the class name and function name to getCNAndUSData () ?

I am not sure here of what is the correct way to deal with such existing code.
Appreciate your comments.

  • 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-17T03:04:31+00:00Added an answer on May 17, 2026 at 3:04 am

    This type of issue (overuse of “if” and “switch” statements) is neatly handled by implementing a strategy pattern with a abstract factory. Basically you want to change the algorithm without changing your implementation and duplicating the code over and over and over.

    Enjoy!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work on code something like this ... HEADERS ... int *var; void child()
I occasionally write code something like this: // file1.cpp #define DO_THIS 1 #if DO_THIS
My code has something like this: HttpFileCollection files Instead of looping through each file
my code is something like this //css li{display:inline-block} //html #li margin and width are
I just discovered a bug where the code looked something like this: char *foo
I have a program that simulates mouse click. Code is something like this: [DllImport(user32.dll,
I have code that looks something like this in javascript: forloop { //async call,
I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
I have something like this : code.js var params = { option1 : encodeURIComponent(text\n
I have something like this in my code: worker.setObject(queue.poll()); I want a queue that

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.