The base class (in the base lib, not owned by me), has upgraded its code and add a new method to support additional use cases.
This is the existing method signature in the base class:
public void Alert(string someAlertString);
With the new release, the base class is supporting a list of AlertObject (at some point the base class might deprecate the string alert)
public void Alert(List<Alert> alertObj);
The base class in lib looks something like this:
public BaseClass {
public void Alert(string message) {
//Print msg on the UI.
}
public void Alert(List<Alert> alerts) { <-- New Addition.
// Loop through each alert and show the list of messages.
}
// Other methods.
}
On my side of the code, I have the alert in multiple places in multiple subclasses (>500 alerts), like this:
public SubClass: BaseClass {
public void Execute(){
// Execute some logic
Alert("This is a warning message."); <-- Call base calls alert
}
}
I want to update all these alert statements to use an AlertObject (and I want to add category only to the new alerts, old alerts can continue using the default category):
public class Alert {
public string message {get;set;}
public string category {get;set;}
}
One way to do this is to define a helper class which takes the existing string and return a List of AlertObject:
public static class AlertHelper {
public static List<Alert> getNewAlert(string msg, string category="Not Defined") {
Alert a = new Alert();
a.message = msg;
a.category = category;
return new List<Alert>() { a };
}
}
Then I can replace all the instance of my Alert with:
base.Alert(AlertHelper.getNewAlert("This is a warning message."))
The one problem I see here is that as the Alert class (in a separate lib) keeps adding properties to support more detailed alerts, I need to keep updating my helper class, and potentially all the places where I call helper class.
I was wondering if there is a better way to design this.