How to force abstract class childs to implement a static method?
A possible approach of combining a static behavior with inheritance or interface implementation is to use the singleton pattern. The access to a singleton object is static, but the object is created with new
like a "normal" object
public interface ISomeInterface { ... }
public class SomeClass : ISomeInterface
{
public static readonly SomeClass Instance = new SomeClass();
private SomeClass()
{
}
// TODO: Implement ISomeInterface
// and/or override members from a base class.
}
Accessing a method of the singleton
ISomeInterface obj = SomeClass.Instance; // Static access to interface.
var y = obj.SomeMethod(x);
You cannot. Static methods are not subject to polymorphic behavior. You cannot even override static methods voluntarily, let alone force a class to override them.
Sorry, but it is impossible. Abstract and/or base classes are all about the object inheritance.
static
methods are specific to one and only one class and are NOT inheritable.