Content deleted Content added
is a design pattern |
De-stubified the article by expanding on the definition of the pattern and giving an example from Java. |
||
Line 1:
This pattern allows a class to implement a '''marker interface''', which exposes some underlying semantic property of the class that cannot be determined solely by the class' methods. 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 good example of a marker interface comes from the [[Java programming language]]. The ''[http://java.sun.com/j2se/1.4.2/docs/api/ Cloneable]'' interface should be implemented by a class if it fully supports the [http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#clone() Object.clone()] method. Every class in Java has the [http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html Object] class at the root of its inheritance hierarchy and so every object instantiated from any class ''has'' an associated clone() method. However, developers should only call clone() on objects of classes which implement the ''Clonable'' interface, as it indicates that the cloning functionality is actually supported in a proper manner.
|