何をしますか
self: #Arakoon_client.client
このコードでは、そのようなオブジェクトの使用方法を意味します
class remote_client ((ic,oc) as conn) =
object(self: #Arakoon_client.client)
何をしますか
self: #Arakoon_client.client
このコードでは、そのようなオブジェクトの使用方法を意味します
class remote_client ((ic,oc) as conn) =
object(self: #Arakoon_client.client)
多くのオブジェクト指向言語には、this
メソッド内からオブジェクトを参照するためのキーワード(C ++)があります。object
OCamlでは、キーワードの後に名前を付けることで、オブジェクトを参照するために使用する名前を選択できます(ここでは、オブジェクトが選択されていますself
)。
OCamlでは、クラスが継承する親に名前を付けることもできます。
class x = object (self)
inherit x_parent as parent
method print = parent#print; print_newline()
end
たとえば、これを使用して、現在のクラスのメソッドによってオーバーライドされた祖先のメソッドを使用できます。前の例でparent#print
は、継承されたメソッドself#print
を呼び出し、現在のメソッドを呼び出します。
最後に、クラスを定義するときに、表記法x
を使用してこのクラスのオブジェクトのタイプを参照できます。#x
ここでは、モジュールで定義された#Arakoon_client.client
クラスのオブジェクトのタイプを参照します。client
Arakoon
In the Arakoon_client module, there is a class type named client
. The expression Arakoon_client.client
refers to this type. As noted in @FabriceLefessant's answer, self
refers to the object itself, and the expression after the colon the type to which the object must conform.
Finally, the #
sign in front of the class typename indicates that the type is not closed (thus the "openly constraints" terms used by @Ontologiae) which means that self
must support at least that interface, but may also hold other methods.
In other words, this is more or less the equivalent of implements Arakoon_client.client
in java.
これは、オブジェクト (インスタンス化された) 自体を表す値 self と、タイプ #Arakoon_client.client によるオープンな制約があることを意味します。
「オブジェクト」には #Arakoon_client.client のすべてのメソッドが必要です