Tuesday, May 15, 2012

Marker Interfaces

Marker interfaces are interfaces which do not define any functions. But by using the language capabilities (for e.g. reflection in java) you can have a certain capabilities if a class implements a marker interface.

for e.g. Suppose you have a marker interface 'MarkerInterface'

public interface MarkerInterface
{
    // Nothing here
}

Now you can check if any class implements the MarkerInterface and provide a functionality by doing something like this:

if(object instanceof MarkerInterface)
{
   // do something specific
}

These are a few interesting links that can tell more about Marker Interfaces:
http://en.wikipedia.org/wiki/Marker_Interface_pattern
http://geekexplains.blogspot.com/2009/10/marker-interface-in-java-what-why-uses.html
http://www.coderanch.com/t/409760/java/java/Marker-Interface
http://www.jguru.com/faq/view.jsp?EID=224126

And of course you can google to find out more..


No comments:

Post a Comment