ObjectSquare [1999 年 4 月号]

[Happy Squeaking!!]


3.Squeak演習:イントロスペクション

3.1 オブジェクトの構造を調べる つづき


クラスについて高度な情報を得る

OrderedCollectionクラスについて、更に高度な情報を得ることにします。
以下を"print it"してみてください。

"クラスの階層をテキスト形式で得る"
OrderedCollection printHierarchy
	=>'
Object ()
	Collection ()
		SequenceableCollection ()

			OrderedCollection (''array'' ''firstIndex'' ''lastIndex'' )
				GraphicSymbol ()
				SortedCollection (''sortBlock'' )'

OrderedCollectionを中心にした、スーパークラス、サブクラスの関係が、テキストとなって表示されます。

"クラスの定義情報をテキスト形式で得る"
OrderedCollection definition
	=>SequenceableCollection subclass: #OrderedCollection
		instanceVariableNames: ''array firstIndex lastIndex ''
		classVariableNames: ''''
		poolDictionaries: ''''
		category: ''Collections-Sequenceable'''

クラスを定義する際に埋めたテンプレート形式でOrderedCollectionクラスについての情報が得られます。

"クラスのコメントをテキスト形式で得る"
OrderedCollection comment
	=>'I represent a collection of objects ordered by the collector.'

これらのメッセージは、実はブラウザがクラスについての情報を表示する際に使われているものです。Smalltalkにおいてはツール自体もSmalltalkで書かれており、開発ツール側のオブジェクト(ブラウザ)が、イントロスペクションによって、任意のオブジェクト(例の場合はOrderedCollection)の表示を可能にしているわけです。

システムブラウザでOrderedCollectionを表示、選択し、クラスに関するポップアップメニューを出してみましょう。


ブラウザからイントロスペクションメッセージを送る

hierarchy、definition、commentの選択をメニューから選んだとき、OrderedCollectionに対して、上で紹介したメッセージがまさに送られているわけです。


© 1999-2001 OGIS-RI Co., Ltd.

Prev.

Index

Next