Utility Pattern

The Utility pattern is a software pattern that is used for utility classes that do not require instantiation and only have static methods. The stateless class is designated as static so that no instance can be created. Good candidates for utility classes are convenience methods that can be grouped together functionally.

Furthermore, methods in Utility classes are usually deterministic. As the Utility class is stateless, all parameters in each method must pass all necessary information to the method.

Example in C#

public static class LogUtil { public static void LogError(String message) { MyLogger logger = new MyLogger; logger.LogError(message); } public static void LogWarning(String message) { MyLogger logger = new MyLogger; logger.LogWarning(message); } public static void LogInfo(String message) { MyLogger logger = new MyLogger; logger.LogInfo(message); } } // A simple example showing how the utility methods are used class MyProgram { static void Main(String args) { if (args.Length > 0) { // Call our utility helper methods. Note that these are static methods // that are called directly off the class. LogUtil.LogError("User ran app with arguments!"); } else { LogUtil.LogInfo("Running program."); Run; } } }

Read more about Utility Pattern:  See Also

Famous quotes containing the words utility and/or pattern:

    Moral sensibilities are nowadays at such cross-purposes that to one man a morality is proved by its utility, while to another its utility refutes it.
    Friedrich Nietzsche (1844–1900)

    His talent was as natural as the pattern that was made by the dust on a butterfly’s wings. At one time he understood it no more than the butterfly did and he did not know when it was brushed or marred. Later he became conscious of his damaged wings and of their construction and he learned to think and could not fly any more because the love of flight was gone and he could only remember when it had been effortless.
    Ernest Hemingway (1899–1961)