跳至內容

幫助類

維基百科,自由的百科全書

幫助類(helper class)用於提供一些功能,但不是其使用者(應用程序或別的類)的主要目標所在。例如在委託模式中的幫助對象(helper object)。

幫助類的一個特例是工具類(utility class),其所有方法都是靜態的。

例子[編輯]

C#的一個工具類例子


public class PrependHelper
{
    // static functions
    public static String meowPrepend(String text)
    {
        return "Meow meow " + text + "!";
    }

    public static String woofPrepend(String text)
    {
        return "Woof woof " + text + "!";
    }

    public static String woohPrepend(String text)
    {
        return "Wooh " + text + "!";
    }
}