Drawbacks of Marker Interface Design Pattern.


A marker interface is a design pattern consisting in an interface with no methods declared. All the classes implementing this interface don’t have to implement a method for the interface(since it doesn’t have an interface), but we can say that the classes implementing the interfaces are marked. For example in Java we have the Serializable interface. It is a Marker Interface, when we create a class in order to mark it as a serializable class, it will implement the serializable, so everyone using it will know that the class is serializable.

However there are 2 major drawbacks:

  • All the subclasses implement a marker, and there is not option to unmark a subclass. For example if the base class is marked as Serializable all the subclasses will be marked as Serializable and there is no option to unmark them by “unimplementing” the Interface.
  • It is dangerous to have several levels of markers (Let’s say we need XmlSerializable and BinarySerializable both extending Serializable). What is a class which is not XmlSerializable? Is it BinarySerializable or NotSerializable?

Starting with Java 1.5 annotations and attributes in .NET can be used instead of Marker Design Pattern. Annotations can be accessed using reflection and can be used to mark not only Classes but also Methods and Attributes.