The '''marker interface pattern''' is a [[design pattern (computer science)|design pattern]] in [[computer science]].
This pattern allows a [[Class (computer science)|class]] to implement a '''marker interface''', which exposes some underlying semantic property of the class that cannot be determined solely by the class' methods[[Method (computer science)|method]]s. 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.
One goodAn example of athe markerapplication interfaceof marker comesinterfaces fromis the [[Java programming language]]. The {{Javadoc:SE|java/lang|Cloneable}} interface should be implemented by a class if it fully supports the {{Javadoc:SE|java/lang|Object|clone()}} method. Every class in Java has the {{Javadoc:SE|java/lang|Object}} class at the root of its inheritance hierarchy and so every object instantiated from any class ''has'' an associated <code>clone()</code> method. However, developers should only call <code>clone()</code> on objects of classes which implement the <code>Cloneable</code> interface, as it indicates that the cloning functionality is actually supported in a proper manner.
Unfortunately there is a problem with this example, namely that in Java you cannot "unimplement" an interface. So if you subclass a class that implements <code>Cloneable</code>, and then do something in your subclass that means it can't be cloned properly, your subclass will still be marked as a <code>Cloneable</code> whether you want it or not. One way out is to throw an Exception (a {{Javadoc:SE|java/lang|CloneNotSupportedException}} is a good idea) in the <code>clone()</code> method, but then you are missing the whole point of the marker interface.
Line 13:
==Critique==
The implementation of this pattern presented abouveabove is rather specific to Java. Other object models support rich ways of quickly querying static data. For example, [[.NET]] supports attributes that can be used to associate any type of data with a class or with its members. As Decadesof before[[J2SE]] 5.NET0, inJava supports [[reflection (computer science)|reflective]] [[annotation]]s that can be used to associate attributes with 1984classes, Theinterfaces, methods, [[MacintoshConstructor OS(computer science)|constructors]], [[Field (computer science)|fields]] and [[Packages in Java|packages]]. Annotation implementedallow a component-basedrich resourceand databasefine-grained associatedassociation withof each[[metadata]] to sourceprogram fileelements.