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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:00:43+00:00 2026-05-13T19:00:43+00:00

I need to be able to conditionally execute a method. I prefer not having

  • 0

I need to be able to conditionally execute a method. I prefer not having a bunch of IF statements throughout my code for several reasons, the most notable is that at a certain point in the future the method will no longer be used.

I am not sure of the best way to do this or what pattern(s) I should choose to accomplish this task.

The application I refer to is an application that is going to replace a legacy system. The legacy code will be turned off and no longer used at some point. Once that point of time comes, I don’t want to have to go back and change any code (if at all possible).

The following is a fictious conceptual example in psuedo of what I mean:

NewSystemEmployee.Save(Employee e)

if (Legacy System Is Running)
{
    LegacySystemEmployee.Save(Employee e)
}

The method NewSystemEmployee.Save always needs to execute. I only want to execute LegacySystemEmployee.Save as long as the Legacy system is running. Once the Legacy system is shutdown, I no longer want to execute LegacySystemEmployee.Save

Once the legacy system goes away, I don’t know how I can accomplish what I want without:

  1. Creating an IF statement before I call LegacySystemEmployee.Save OR
  2. Removing every call to LegacySystemEmployee.Save method OR
  3. Changing LegacySystemEmployee.Save method so that it is a stub and nothing more

I also have a requirement that the NewSystemEmployee class does not refer in any way to the LegacySystemEmployee class.

Any suggestions?

Thanks so much

  • 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-13T19:00:44+00:00Added an answer on May 13, 2026 at 7:00 pm

    At first glance this calls for the Strategy pattern (or in fact Template Method), possibly with a Factory Method to control which strategy to use. Example (in pseudo-Java):

    class Saver {
        protected void LegacySave(Employee e)  {}
        public final void Save(Employee e) {
            NewSystemEmployee.Save(e);
            LegacySave(e);
        }
    }
    
    class LegacySaver extends Saver {
        protected void LegacySave(Employee e) {
            LegacySystemEmployee.Save(e);
        }
    }
    

    Since at some point in time you will no more need the legacy call, it makes sense to implement the default LegacySave as empty. Then you can trivially use the class like this:

    getSaver().save(employee);
    

    where getSaver() is the factory method which silently decides which Saver implementation to present to its caller. Trivially it can get the class name from a config file.

    Question is, how do you need to change the behaviour: runtime, or by restarting the application? If you can restart the application, it is easy to change that one line in the configuration which controls the strategy to use. Changing behaviour on-the-fly is slightly more tricky, but doable.

    A lot depends on what programming language you use. E.g. in Java / C++ / C# you can easily accomplish what you want with dependency injection; in some other languages it might not be that easy.

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

Sidebar

Related Questions

I need to be able to access a list throughout my Rails project. For
I need to be able to conditionally require certain fields to be validated, based
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to
I need to be able to search through multiple 2D arrays and search the
I need to be able to create an id for a hyperlink. I have
I need to be able to strip out a condition in a string, here
I need to be able do the following on a TR: onmouseover highlight the
I need to be able to map out in coordinates real world cities and
I need to be able to change the filebrowserUploadUrl of CKEditor when I change

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.