An interface would not be as good, because then there is no automatic path for each class in the hierarchy on top of the interface to provide its own implementation, if only:
- Base class declares methods as virtual
- Each producing class reimplement the interface
Then an additional complication of identification of each class implementation is added - reflection is more complicated.
In addition, after entering the interface, it is assumed that all classes in the hierarchy are serializable, but this does not always and should not always be so. It is quite correct to derive a non-serializable class from a serializable base (under controlled conditions), but this is effectively prevented using the interface or virtual methods.
Thus, the use of attributes provides the most expressive and most flexible way to implement serialization.
source share