Now, if the title sounds weird to you, consider this code, I was reviewing today (simplified):
public class MyService(
IHttpClientFactory httpClientFactory) :
BaseService(), // WTF? a Method?
IMyService
{
//no explicit constructor, has default constructor
//....
}
This actually compiles! The MyService
class inherits something from BaseService
, apparently a method, and implements the IMyService
interface.
BaseService
is an abstract class, only defining some static objects and some literal strings:
public abstract class BaseService
{
public static List<MaintenanceWindow> RegisteredMaintenanceWindows = new List<MaintenanceWindow>();
protected static string CERT_SERVICE_URI = "https://cert.example.com";
public static string DEFAULT_DOMAIN = "default.example.com";
// ....
}
What does MyService
inherit here?
- There is no actual method in the base class
- Does it inherit the (default) constructor?
I have never observed this kind of C# inheritance, and also these inheritance docs from Microsoft do not mention it.