イフコンピュータ > MINERVA > マニュアル > レファレンス > オブジェクト

オブジェクト

MINERVA
ifcomputer logo
f
Expert Services on the Web

オブジェクト指向プログラミングは、述語の内部状態を隠しておいて、 その状態を操作するのに適しています。

MINERVAでは、クラスとそのメソッドを定義することができます。

あるクラスのあるオブジェクトには、 黒板データ、つまり、bb_ で始まる 述語を使ってアクセスすることができる内部状態があります。

例:

:- class(counter).

Counter :: init :- bb_put(Counter, index, 0).

Counter :: init(InitialValue) :- bb_put(Counter, index, InitialValue).

Counter :: get(Value) :- bb_get(Counter, index, Value).

Counter :: set(Value) :- bb_put(Counter, index, Value).

Counter :: next(Value) :- Counter :: get(OldValue), NewValue is OldValue + 1, Counter :: set(NewValue), Value = NewValue.

:- endclass.

新しいオブジェクトを作るために、MINERVAコンパイラは、これらの述語を処理し、 create_CLASS/1/2の述語を生成します。

結果として生成された述語は、

	Object::Method(Arg1,..,ArgN)
となります。 ここで、 Objectは、create_object/2で生成され、Methodは、アトム あるいは複合項でなければなりません。

上の例は、古典的なPrologでは以下のようになります。

	create_counter(10,Counter),
	Counter :: next(Index)

上の例は、関数表記では、以下のようになります。

	Counter <- create_counter(10),
	Index <- Counter::next,
	...

document: http://www.ifcomputer.co.jp/MINERVA/Manual/Reference/Objects/print_jp.html
published 2008/9/1 update 2003/2/26 (c) 1996-2006 IF Computer Japan
IF Computer 〒113-0022 Tel 03-5814-3352 start (AT) ifcomputer.com
Customer Support 東京都文京区千駄木5-28-2   http://www.ifcomputer.co.jp
戻る> managed with ubiCMS