I have a set of classes with the same functions, but with different logic. However, each class function can return multiple objects. Is it safe to set the return type as an interface?
Each class (everyone uses the same interface) does this with a different business logic.
protected IMessage validateReturnType; <-- This is in an abstract class
public bool IsValid() <-- This is in an abstract class
{
return (validateReturnType.GetType() == typeof(Success));
}
public IMessage Validate()
{
if (name.Length < 5)
{
validateReturnType = new Error("Name must be 5 characters or greater.");
}
else
{
validateReturnType = new Success("Name is valid.");
}
return validateReturnType;
}
Are there pitfalls with a module checking the type of function return? Also, is it considered bad design to have features that need to be run in order for them to succeed? In this example, check () must be performed before IsValid (), otherwise IsValid () always returns false.
Thank.
source
share