ルーム情報 : "droom" (291件)
最近更新されたメモ一覧 :
docs
見出し一覧 :
被リンクメモ一覧 : (1件)
[index]
[Home] [List] [Recent] [Orphan] [Help] [Edit] [Remove]

AppleScript : Chain of Responsibility

AppleScriptでのChain of Responsibilityを考えてみました。
元ネタはHAPPY Macintosh Developing TIME!オブジェクト指向の言語比較論です。

実装されていないハンドラの呼び出しに対応する方法がないので、C++での実装(簡単な方)と同じく仮想関数的な方法で実装しています。欠点としては、やはりハンドラを増やすたびにhandlerObjスクリプトオブジェクトに手を加える必要があることでしょうか。

--3種類のスクリプトオブジェクトの親となるスクリプトオブジェクト
--インスタンスは1つのみで、複数のオブジェクトから共有される
script handlerObj
    on previewReq()
        tell my target to previewReq()
    end previewReq
    on printReq()
        tell my target to printReq()
    end printReq
    on helpReq()
        tell my target to helpReq()
    end helpReq
end script

on run
    set aApp to applicationObj()
    set aDialog to dialogObj(aApp)
    set aButton to buttonObj(aDialog)
    
    tell aButton to helpReq()
end run

--ボタンを表すスクリプトオブジェクトの生成ハンドラ
on buttonObj(aDialog)
    script buttonObj
        property parent : handlerObj
        property target : aDialog
        on previewReq()
            return "button's previewReq"
        end previewReq
    end script
end buttonObj

--ダイアログを表すスクリプトオブジェクトの生成ハンドラ
on dialogObj(aApplication)
    script dialogObj
        property parent : handlerObj
        property target : aApplication
        on printReq()
            return "dialog's printReq"
        end printReq
    end script
end dialogObj

--アプリケーションを表すスクリプトオブジェクトの生成ハンドラ
on applicationObj()
    script applicationObj
        property parent : handlerObj
        on helpReq()
            return "application's helpReq"
        end helpReq
    end script
end applicationObj
[Home] [List] [Recent] [Orphan] [Help] [Edit] [Remove]
-->