Thursday, September 16, 2010

Marker Interface

An interface that consists of no method....... or an interface having nothing in the body is called marker interface. These interfaces can be useful in the scenarios while we need to mark some kind of implementations of derived class objects for different kinds of behavior.

e.g Let C be a class

C1 and C2 inherits C and also C2 implements Imarker interface. 
now suppose the object to be realistic in real world and the objects of class that implements Imarker interface are always intelligent entities.

now let 5 objects of C1 and 3 objects of C2 go for competition and clearly objects of C2 are winner. Then to check which object is winner which is not, instead of checking property of individual we just will check which is object is assignable to reference of Imarker interface. which removes lot of checks in case of complex scenarios.

No comments: