3

何をしますか

self: #Arakoon_client.client 

このコードでは、そのようなオブジェクトの使用方法を意味します

class remote_client ((ic,oc) as conn) =

object(self: #Arakoon_client.client)
4

3 に答える 3

6

多くのオブジェクト指向言語には、thisメソッド内からオブジェクトを参照するためのキーワード(C ++)があります。objectOCamlでは、キーワードの後に​​名前を付けることで、オブジェクトを参照するために使用する名前を選択できます(ここでは、オブジェクトが選択されています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クラスのオブジェクトのタイプを参照します。clientArakoon

于 2013-01-03T08:08:36.417 に答える
2

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.

于 2013-01-03T12:50:55.737 に答える
2

これは、オブジェクト (インスタンス化された) 自体を表す値 self と、タイプ #Arakoon_client.client によるオープンな制約があることを意味します。

「オブジェクト」には #Arakoon_client.client のすべてのメソッドが必要です

于 2013-01-02T16:20:59.833 に答える