Let’s say I have an interface called “XMLControl”, and I need every class that implements it to also implement ISerializable. Is there any OO approach to force this?
It may also be possible to put XMLControl as an abstract class although slightly less preferable. What’s the best approach?
I was thinking of putting a static method in XMLControl like so:
static void LoadFromXML(SerializableClass);
but looking for better ideas.
Thanks.
You could make the
XMLControlinterface implement theISerializableinterface:This way you are forcing all implementors of the
IXmlControlinterface to also implementISerializable.Also notice that standard .NET naming convention dictate that interface names should start with a capital
I. So this interface would better be calledIXmlControl.