Marker interface pattern: Difference between revisions

Content deleted Content added
Misstype: writeObject0() -> writeObject()
Critique: Bullet Formatting
Line 11:
A '''major problem''' with '''marker interfaces''' is that an interface defines a contract for implementing classes, and that contract is inherited by all subclasses. This means that you cannot "unimplement" a marker. In the example given, if you create a subclass that you do not want to '''serialize''' (perhaps because it depends on transient state), you must resort to explicitly throwing <code>NotSerializableException</code> (per <code>ObjectOutputStream</code> docs).
 
A better solution is for the language to support [[metadata]] directly:
A better solution is for the language to support [[metadata]] directly. The [[.NET Framework|.NET framework]] supports attributes that can be used to associate any type of data with a class or with its members. Java, as of Java 5 (1.5), also provides annotations on classes, methods, and member variables that may be accessed from an instance using reflection.
 
* The [[.NET Framework|.NET framework]] supports attributes that can be used to associate any type of data with a class or with its members.
In [[Python (programming language)|Python]], the use and term '''marker interfaces''' is common in [[Zope 3]] and [[Plone (software)|Plone]]. Interfaces are declared as metadata and subclasses can use <code>implementsOnly</code> to declare they do not implement everything from their super classes.
A better solution is for the language to support [[metadata]] directly. The [[.NET Framework|.NET framework]] supports attributes that can be used to associate any type of data with a class or with its members.* Java, as of Java 5 (1.5), also provides annotations on classes, methods, and member variables that may be accessed from an instance using reflection.
* In [[Python (programming language)|Python]], the use and term '''marker interfaces''' is common in [[Zope 3]] and [[Plone (software)|Plone]]. Interfaces are declared as metadata and subclasses can use <code>implementsOnly</code> to declare they do not implement everything from their super classes.
 
== See also ==