The bottom class (within the base lib, not owned by me), has upgraded its code and add a brand new methodology assist further use cases-
Current methodology signature in base class-
public void Alert(string someAlertString);
With the brand new launch, the bottom class is supporting a listing of AlertObject (sooner or later the bottom class may depricate the string alert)
public void Alert(Checklist<Alert> alertObj);
On my facet of the code, I’ve the alert in a number of locations, like this –
base.Alert("It is a warning message.")
I need to replace all these alert statements to make use of an AlertObject (and I need to add class solely to the brand new alerts, previous alerts can proceed utilizing the default class):
public class Alert {
public string message {get;set;}
public string class {get;set;}
}
A technique to do that is to outline a helper class which takes the prevailing string and return a Checklist of AlertObject –
public static class AlertHelper {
public static Checklist<Alert> getNewAlert(string msg, string class="Not Outlined") {
Alert a = new Alert();
a.message = msg;
a.class = class;
return new Checklist<Alert>() { a };
}
}
Then I can change all of the occasion of my Alert with –
base.Alert(AlertHelper.getNewAlert("It is a warning message."))
The one downside I see right here is that because the Alert class (in a separate lib) retains including properties to assist extra detailed alerts, I must preserve updating my helper class, and doubtlessly all of the locations the place I name helper class.
I used to be questioning if there’s a higher approach to design this.