|
p:abstract
|
-
Duck-Typing ist ein Konzept der Objektorientierung, das die Anwendbarkeit bestimmter Verfahren nicht an die Ableitung der Klasse von einer bestimmten Superklasse oder der förmlichen Implementierung einer Spezifikation knüpft, sondern an das Vorhandensein bestimmter Merkmale, in Anlehnung an James Whitcomb Rileys Gedicht
was übersetzt bedeutet: „Wenn ich einen Vogel sehe, der wie eine Ente läuft, wie eine Ente schwimmt und wie eine Ente schnattert, dann nenne ich diesen Vogel eine Ente.“ Duck-Typing ist charakteristisch für objektorientierte Skriptsprachen wie Python und Ruby.
= Beispiele ="
(de)
-
In computer programming, duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class. The name of the concept refers to the duck test, attributed to James Whitcomb Riley, which may be phrased as follows:
:If it walks like a duck and quacks like a duck, I would call it a duck.
In duck typing one is concerned with just those aspects of an object that are used, rather than with the type of the object itself. For example, in a non–duck typed language, one can create a function that takes an object of type Duck and calls that object's walk and quack methods. In a duck typed language, the equivalent function would take an object of any type and call that object's walk and quack methods. If the object does not have the methods that are called then the function signals a run-time error. It is this action of any object having the correct walk and quack methods being accepted by the function that evokes the quotation and hence the name of this form of typing.
(en)
-
In computer programming, duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class. The name of the concept refers to the duck test, attributed to James Whitcomb Riley, which may be phrased as follows:
:If it walks like a duck and quacks like a duck, I would call it a duck.
In duck typing one is concerned with just those aspects of an object that are used, rather than with the type of the object itself. For example, in a non–duck typed language, one can create a function that takes an object of type Duck and calls that object's walk and quack methods. In a duck typed language, the equivalent function would take an object of any type and call that object's walk and quack methods. If the object does not have the methods that are called then the function signals a run-time error. It is this action of any object having the correct walk and quack methods being accepted by the function that evokes the quotation and hence the name of this form of typing."
(en)
-
ダック・タイピング()とは、Smalltalk・Python・Rubyなどのいくつかの動的型付けオブジェクト指向プログラミング言語に特徴的な型付けの作法のことである。それらの言語ではオブジェクト(変数の値)に何ができるかはオブジェクトそのものが決定する。つまり、オブジェクトがあるインタフェースのすべてのメソッドを持っているならば、たとえそのクラスがそのインタフェースを宣言的に実装していなくとも、オブジェクトはそのインタフェースを実行時に実装しているとみなせるということである。それはまた、同じインタフェースを実装するオブジェクト同士が、それぞれどのような継承ヒエラルキーを持っているかとは関係なく、相互に交換可能であるという意味でもある。
この用語の名前は「ダック・テスト」に由来する。
"If it walks like a duck and quacks like a duck, it must be a duck"(もしもそれがアヒルのように歩き、アヒルのように鳴くのなら、それはアヒルである)
デーブ・トーマスはRubyコミュニティで初めてこの言葉を使ったと考えられている。
C++のtemplateはダック・タイピングの静的版である。例えば、iteratorはIterator基底クラスのようなものからメソッドを継承しているわけではない。
もう1つ、ダック・タイピングに似たアプローチにOCamlのstructural subtypingがある。メソッドのシグネチャが互換ならば、宣言上の継承関係は関係なく、オブジェクトの型も互換であるというものである。これはOCamlの型推論システムによってコンパイル時にすべて決定される。"
(ja)
|
|
rdfs:comment
|
-
Duck-Typing ist ein Konzept der Objektorientierung, das die Anwendbarkeit bestimmter Verfahren nicht an die Ableitung der Klasse von einer bestimmten Superklasse oder der förmlichen Implementierung einer Spezifikation knüpft, sondern an das Vorhandensein bestimmter Merkmale, in Anlehnung an James Whitcomb Rileys Gedicht"
(de)
-
In computer programming, duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class. The name of the concept refers to the duck test, attributed to James Whitcomb Riley, which may be phrased as follows:
(en)
-
ダック・タイピング()とは、Smalltalk・Python・Rubyなどのいくつかの動的型付けオブジェクト指向プログラミング言語に特徴的な型付けの作法のことである。それらの言語ではオブジェクト(変数の値)に何ができるかはオブジェクトそのものが決定する。つまり、オブジェクトがあるインタフェースのすべてのメソッドを持っているならば、たとえそのクラスがそのインタフェースを宣言的に実装していなくとも、オブジェクトはそのインタフェースを実行時に実装しているとみなせるということである。それはまた、同じインタフェースを実装するオブジェクト同士が、それぞれどのような継承ヒエラルキーを持っているかとは関係なく、相互に交換可能であるという意味でもある。"
(ja)
|