![]() |
[1999 年 7 月号] |
[Happy Squeaking!!]
マルチビューとしてCounterアプリケーションを起動するにあたって便利なユーティリティとなるクラスを作成しましょう。これでワークスペースにビュー起動用のメッセージ群をいちいち書かずに済むようになります。
以下のようにクラス定義を行います。
Object subclass: #CounterLauncher instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'MVC tutorial'
CounterLauncherは、ユーティリティクラスとして、簡単に使えることを考えています。そこでインスタンスをいちいち生成しなくともCounterLauncherが使えるように、クラス操作やクラス属性を追加していくことにします。
まず、クラスインスタンス変数として、counterを定義します。ここにはビューが同時に参照するモデルとしてCounterのインスタンスが入ります。
ブラウザを"class"側に合わせて以下のようにテンプレートに記入し、"accept"します。
CounterLauncher class instanceVariableNames: 'counter '
次に操作を追加します。(これらもすべて"class"側で行います)
まずは定義したcounterの初期化操作です。
(CounterLauncher class >> class initializationカテゴリ)
initialize counter := Counter new
アクセス用の操作も定義しましょう。
次に更新受け取りメッセージを作成します。
(CounterLauncher class >> accessingカテゴリ)
counter ^counter
counter: aCounter counter := aCounter
最後に起動用の操作を定義します。引数としてビューのインスタンスを受け取り、同一モデル(counter)を参照させて起動するようにします。
(CounterLauncher class >> actionsカテゴリ)
launchBy: aCounterView aCounterView model: self counter. aCounterView label: aCounterView name. aCounterView maximumSize: 200 @ 100. aCounterView minimumSize: 50 @ 30. aCounterView borderWidth: 5. aCounterView backgroundColor: Color yellow. aCounterView controller open.
これで完成です。
FileIn: CounterLauncher.st (<=Click)
© 1999-2001 OGIS-RI Co., Ltd. |
|