我在派生类的不同实例中有公共(public)数据。 所以为了共享公共(public)数据属性,我在基类中将它们设为静态。 但是静态公共(public)属性不能在接口(interface)中声明。 如果我们尝试,我们会得到错误:
"cannot implement an interface member because it is static."
对于这种需求,是否有任何已知的设计模式或最佳实践?
最佳答案
最好改用抽象基类。
关于C# : Static Members in Base Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13512128/