There are a lot of opinions regarding this topic (here and here for example). And even though the ASP.NET team usually use interfaces, I can think of a few reasons why they chose for an abstract class in this case:
Versioning
I don't expect the HttpContext
class to change a lot, but abstract classes version easier than interfaces (they actually don't version at all) since they can be partially implemented using the virtual
keyword.
Encapsulation
Abstract classes encapsulate a set of functionalities where interfaces provide more of a contract for a certain functionality. Classes may only implement one abstract class, which makes sense for a HttpContext
implementation, such as the DefaultHttpContext
.
Backwards compatibility
Although ASP.NET Core is complete rewrite of ASP.NET, developers are used to program against the HttpContext
class for years. Both classes share a lot of the characteristics.
Take in mind that I'm just guessing here, perhaps some folks of the ASP.NET team could enlighten us.