Adapterパターン

Nemerleの特徴を利用して変則的に実装してみました。

using Nemerle.Utility;

// 移譲先
public class Banner {
    text : string;

    public this (text : string) {
        this.text = text;
    }
    public ShowWithParen () : void {
        System.Console.WriteLine ($"($text)");
    }
    public ShowWithAster () : void {
        System.Console.WriteLine ($"*$text*");
    }
}

// アダプタのインタフェース
public interface IPrint {
    // 関数型(≒C#delegate)のプロパティを持つ
    // void -> void は 引数void、戻り値voidの関数を意味する 
    PrintWeak : void -> void { get; }
    PrintStrong : void -> void { get; }
}

public class Print : IPrint {
    banner : Banner;
    [Accessor]
    printWeak : void -> void;
    [Accessor]
    printStrong : void -> void;

    public this (text : string) {
        // Bannerクラスへ委譲
        banner = Banner (text);
        printWeak = banner.ShowWithParen;
        printStrong = banner.ShowWithAster;
    }
}

def print = Print ("Hello");

print.PrintWeak ();
print.PrintStrong ();

/* 結果
 (Hello)
 *Hello*
 */