index, AV, AppleScript, Bicycle, Cinema, DTM, Dairy, Dev, Fashion, Fitness, Game, Health, Help, Lyrics, Meal, Motor, Motorcycle, Music, Objective-C, PC, PDA, Phone, Robot, S15S, Stationary, Swift, Text, Travel, V36, Watch
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