Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Monday, December 15, 2008

Using static strings and objects to increase performance and maintainence

I found this global variable article below to help me with using static strings and objects to increase performance and maintainence.

For example, suppose I have an error message, "Error: ", that I might want to change to "There was a problem: ". Instead of search and replace n times, I could just use a static string variable to change the string value.

Sample Global class:

/// <summary>
/// Summary description for Global
/// </summary>
public static class Global
{
public static string CSS_HIDDEN
{
get { return "hidden"; }
}
public static string CSS_EMPTY
{
get { return string.Empty; }
}
public static string CSS_CONTENT
{
get { return "content1"; }
}
public static string ERROR_HEADER_HTML
{
get { return "<red>There was a problem:</red></br>"; }
}
public static string ERROR_HEADER
{
get { return "There was a problem:"; }
}
}
Then one just accesses it with Global.ERROR_HEADER. Notice that there is no declarative instantiation for the static class.

Reference: http://dotnetperls.com/Content/Global-Variables-ASPNET.aspx

No comments: