[BASIC EDITORS, my first post was somewhat misleading. My sentences]
For a class such as:
public class DatabaseResult{
public bool Successful;
public string ErrorMessage;
public static DatabaseResult Failed(string message) {
return new DatabaseResult{
Successful = true,
ErrorMessage = message
};
}
}
How can I implement subclasses to add additional properties to represent data related to a particular operation (for example, MatchedResult in the case of a SELECT query) without having to implement this static failure function? If I try to use regular inheritance, the return type will have a parent class. For instance:
DoThingDatabaseResult : DatabaseResult {
public IEnumerable<object> SomeResultSet;
public static Successful(IEnumerable<object> theResults){
return new DoThingDatabaseResult {
Successful = true,
ErrorMessage = "",
SomeResultSet = theResults
};
}
}
The goal is to avoid having to copy the old Failed function for each implementation of the subclass.
source
share