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

  • Home
  • SEARCH
  • 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 6324727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:45:31+00:00 2026-05-24T16:45:31+00:00

This happens to me every once in a while and I always end up

  • 0

This happens to me every once in a while and I always end up solving it the same way and then wishing for a cleaner way.

I start out with a calls to related utility functions, followed by and update call.

SynchA();
SynchB();
UpdateLastTime();

Then later I add check boxes so I have:

if(synchA.Checked)
{
  SynchA();
}
if(synchB.Checked)
{
  SynchB();
}

BUT now I only want to call UpdateLastTime() of ONE OR BOTH the two executed so invariably I end up with:

bool synchHappened = false;
if(synchA.Checked)
{
  SynchA();
  synchHappened = true;
}
if(synchB.Checked)
{
  SynchB();
  synchHappened = true;
}
if(synchHappened)
{
  UpdateLastTime();
}

That final step always bothers me because I’m spreading this one bool around to three branches of logic.

Is there some obvious better approach to the above logic/scenario that I could use?

  • 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-24T16:45:32+00:00Added an answer on May 24, 2026 at 4:45 pm

    The main goal would be – each time as logic has changed – code should be affected at least as possible.
    So you’ve to structure such things once and then it will work for you.

    In your particular case I would suggest to Keep It Simple (no Strategy Pattern, and so on), so
    extract and encapsulate a logic of switches into the properties. So each time as requirements will be changed – you’ve to update either logic of particular switch or main logic itself.

    Switches with encapsulated rules:

    bool IsUpdateLastTime
    {
     get
     {
        // logic here even can be fully or partially injected 
        // as Func<bool>
        return this.IsSyncA || this.IsSyncB;
     }
    }
    
    bool IsSyncA { get { return synchA.Checked; } }
    bool IsSyncB { get { return synchB.Checked; } }
    

    Main logic:

    if (this.IsUpdateLastTime)
    {
      this.UpdateLastTime();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This happens like once every 100 times I open my app. Normally all the
This happens to me quite frequently...at least once every 1 or 2 weeks...and it
I'm wondering if anyone knows how this happens? My website is down, but every
I am authenticating users in ldap, but this happens only once, when user is
Every once in a while I try to add a new data model version,
Every once in a while, when I'm editing an aspx or ascx page, Visual
Every once and a while, I have to get the basics to a language
This happens repeatedly and is very annoying. I upload some PHP code to a
This happens after I hit Build and Go to run my app on my
This happens in IDLE and Windows 7 RC1 (if that helps). Here is the

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.