Hey all,
I'm in the process of architecting a library that will be used in multiple releases of a product, and part of its job is to augment some of the functionality that doesn't exist in .NET 1.1, since we're required to use it. Probably the best example of this is the String.IsNullOrEmpty method, whose functionality we rely on fairly heavily.
The String class in .NET is sealed; I've thought about using either the Adapter or Decorator patterns to extend the functionality of the class by wrapping the original string, but I'm not convinced that this is a very intuitive approach for what I'm trying to do. I've also looked at another post on StackOverflow about a similar question, but it again raises the issue I just mentioned.
I could definitely use Adapter to create the functionality I'm looking for, but I can't imagine doing this for every string:
bool isEmpty = new StringExtensionAdapter(myXmlNode.SelectSingleNode(myXpathString)).IsNullOrEmpty();
if (isEmpty)
{
// Do something
}
I don't necessarily dislike this approach, but it seems like it results in a lot of memory management where a different solution might be better. Also, I'm not crazy about creating a "StringUtility" library since that approach takes me further away from the object-oriented design I'd like to follow.
Any input would be helpful; if I'm just crazy and should use one of these approaches, let me know. I'm searching more for best practices than a solution, since I have several.