The marker interface pattern is a design pattern in computer science, used with languages that provide run-time type information about objects. It provides a means to associate metadata with a class where the language does not have explicit support for such metadata. To use this pattern, a class implements a marker interface, and methods that interact with instances of that class test for the existence of the interface.
| Property | Value |
| dbpprop:abstract
|
- The marker interface pattern is a design pattern in computer science, used with languages that provide run-time type information about objects. It provides a means to associate metadata with a class where the language does not have explicit support for such metadata. To use this pattern, a class implements a marker interface, and methods that interact with instances of that class test for the existence of the interface. Whereas a typical interface specifies functionality (in the form of method declarations) that an implementing class must support, a marker interface need not do so. The mere presence of such an interface indicates specific behavior on the part of the implementing class. Hybrid interfaces, which both act as markers and specify required methods, are possible but may prove confusing if improperly used. An example of the application of marker interfaces from the Java programming language is the Serializable interface. A class implements this interface to indicate that its non-transient data members can be written to an ObjectOutputStream. The ObjectOutputStream private method writeObject contains a series of instanceof tests to determine writeability, one of which looks for the Serializable interface. If none of these tests pass, the method throws a NotSerializableException.
- Eine Markierungsschnittstelle (englisch Marker Interface oder Tag Interface) ist ein Entwurfsmuster, das dem Programm zur Laufzeit Informationen über ein Objekt liefert. Dies bietet die Möglichkeit einer Klasse Metadaten hinzuzufügen, obwohl die Programmiersprache dies nicht explizit unterstützt. In diesem Muster implementiert eine Klasse eine Schnittstelle welche meistens keine Funktionalität in der Form von Methodendeklarationen definiert. Andere (klassenfremde) Methoden testen bei einer Interaktion mit der Klasse, ob die Markierungsschnittstelle für die (instanzierte) Klasse existiert. Die Anwesenheit einer solchen Schnittstelle definiert ein bestimmtes Verhalten für die implementierende Klasse. Hybridschnittstellen welche sowohl als Markierung fungieren, als auch Methoden deklarieren sind grundsätzlich möglich, aber können bei falscher Verwendung verwirrend sein. Ein Beispiel für die Verwendung von Markierungsinterfaces in der Programmiersprache Java ist die Serializable-Schnittstelle, welche signalisiert, dass die persitenten Attribute der implementierende Klasse in einen ObjectOutputStream geschrieben werden können. Die Methode ObjectOutputStream. writeObject enthält einige instanceof-Tests, welche prüfen, ob das übergebene Objekt die Schnittstelle Serializable enthält. Falls dies nicht der Fall ist, wird eine NotSerializableException geworfen.
- マーカーインタフェース ({{lang|en|marker interface)とは、オブジェクト指向プログラミングにおいて、中身が空になっているインタフェースのこと。 Javaなどの言語ではよく使われる。メソッドやフィールドが一切定義されていないインタフェースのことであるJavaにおいてマーカーインタフェースとなっているインタフェースには例としてオブジェクトの直列化に使用する{{Javadoc:SE|java/io|Serializable、オブジェクトをクローニングできることを示す{{Javadoc:SE|java/lang|Cloneable、リストオブジェクトにおいて高速なランダムアクセスを実現する{{Javadoc:SE|java/util|RandomAccess、データがなく名前だけを持つマーカーアノテーションなどがある。 Javaにおけるマーカーインタフェースの書き方の例を示す。 interface MarkerInterface { また、Javaにおけるマーカーアノテーションの書き方の例は以下のようになる。 @interface MarkerAnnotation {
|
| dbpprop:hasPhotoCollection
| |
| dbpprop:javadocSeProperty
|
- ObjectOutputStream
- Serializable
- java/io
|
| dbpprop:wikiPageUsesTemplate
| |
| rdf:type
| |
| rdfs:comment
|
- The marker interface pattern is a design pattern in computer science, used with languages that provide run-time type information about objects. It provides a means to associate metadata with a class where the language does not have explicit support for such metadata. To use this pattern, a class implements a marker interface, and methods that interact with instances of that class test for the existence of the interface.
- Eine Markierungsschnittstelle (englisch Marker Interface oder Tag Interface) ist ein Entwurfsmuster, das dem Programm zur Laufzeit Informationen über ein Objekt liefert. Dies bietet die Möglichkeit einer Klasse Metadaten hinzuzufügen, obwohl die Programmiersprache dies nicht explizit unterstützt. In diesem Muster implementiert eine Klasse eine Schnittstelle welche meistens keine Funktionalität in der Form von Methodendeklarationen definiert.
|
| rdfs:label
|
- Marker interface pattern
- Markierungsschnittstelle
- マーカーインタフェース
|
| owl:sameAs
| |
| skos:subject
| |
| foaf:page
| |
| is dbpprop:redirect
of | |
| is owl:sameAs
of | |