I use C# language, but I think this question is not limited with language. I have the next function and method to return image name:
public Func<string> GetImageNameFunc { get; set; }
private string getImageName()
{
if (GetImageNameFunc != null)
{
string imageName = GetImageNameFunc();
if (!string.IsNullOrEmpty(imageName))
{
return imageName;
}
}
return "default.png";
}
In the past the logic was next:
- use GetImageNameFunc function to override image name
- return null or empty string to specify, that you need to use default image
Now I'd like to give one more possibility to user: he must be able to specify, that he wouldn't like to have image at all. So, he must be able to return some value from function, which would mean, that he doesn't wish to get image at all: let's say, Image.None.
I guess I can use some constant like
public const string NoImageName = "|";
, which would have a value that is inconsistent for image, and specify this constant in event comments. But I don't really like that way.
Any suggestions?
|) means that the consumer of this functionality must be able to understand what that means and do something with it when it sees it. Since that's the case, I'd just stick to returningnulland handle the default image inside that consumer. By consumer, it could be another method within the same class.boolparameter asking if he wants to backout to a default value if no image exists?