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:
- Creating an IF statement before I call
LegacySystemEmployee.Save
OR - Removing every call to
LegacySystemEmployee.Save
method OR - 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