I have common data across different instances of derived classes.
So to share the common data properties, I made them static in base class.
But the static common properties can not be declared in the interface.
If we try, we get the error:
“cannot implement an interface member because it is static.”
Is there any known design pattern or a best practice for this kind of requirement?
Interface defines just that, an interface. As soon as you have anything “real”, be it method implementation or shared data, you need a class, an abstract one in this case.
Alternative would be to keep the interface, but add singleton to hold the data related to the classes which implement the interface. If you need to use an interface, then this is the way to go, I think. Just name the singleton so, that it is obvious it’s logically linked to the interface, and document, that implemenations of the interface should use it.
In your case, static class with the data might be enough, instead of full singleton implementation, but I will not get into this here, the whole “static classes vs singletons” is somewhat controversial subject.