Marker interface pattern

A marker interface (English marker interface or tag Interface) is a design pattern that at runtime the program provides information about an object. This provides the possibility to add a class metadata, although this is not explicitly supported programming language.

In this pattern, a class implements an interface which usually no functionality in the form of method declarations defined. Other ( alien class ) methods to test for an interaction with the class whether the marker interface for the ( instantiated ) class exists. The presence of such an interface defines a specific behavior for the implementing class. Hybrid interface which act both as a marker, as well as methods are declared in principle possible, but can be confusing if used incorrectly.

An example of the use of marker interfaces in the Java programming language is the Serializable interface, which indicates that the persistent attributes of the implementing class can be written to an ObjectOutputStream. The method ObjectOutputStream.writeObject () contains some instanceof tests, which check whether the passed object contains the Serializable interface. If this is not the case, a NotSerializableException is thrown.

Criticism

550372
de