Personally, I believe that inheritance is a great tool that, when used wisely, can greatly simplify the code.
However, it seems to me that many modern tools do not like inheritance. Take a simple example: Serialize a class in XML. Once inheritance is involved, it can easily turn into a mess. Especially if you are trying to serialize a derived class using a base class serializer.
Of course, we can get around this. Something like an attribute KnownTypeand stuff. Besides the fact that you experience itching in your code that you must remember to update every time you add a derived class, it also fails if you get a class from outside your scope that was not known at compile time. (Well, in some cases, you can still get around this, for example, using the NetDataContract serializer in .NET. Of course, a certain advancement.)
In any case, the basic principle still exists: serialization and inheritance are poorly combined. Given the huge list of programming strategies that have become possible and even common in the last decade, I am tempted to say that inheritance should be avoided in areas related to serialization (in particular, deletion and databases).
It makes sense? Or did I mess it up? How do you handle inheritance and serialization?
mafu source
share