Replies: 2 comments 18 replies
-
You can define properties on interfaces, including with default implementations. However, interfaces cannot contain state. They have no storage for it, and attempting to support that would bring with it all of the complexity (and problems) of multiple inheritance. As for the web, that sounds like a question for ASP.NET or whatever framework you use. There's nothing about the language that forbids their use in such cases. |
Beta Was this translation helpful? Give feedback.
-
Multiple inheritance is just one way to compose code. I'd like to explore better and friendly way to compose codes in more dimensions. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Default methods inside interfaces provide a neat way for composition. Since C# does not have multiple inheritance, we can extract common functionality into separate interfaces and add them to existing classes easily.
But they are very limited. Two points:
HttpContext
orreturn Ok
in our default methods.Can these two new features be added to the C# language? Can we have
ISeoController
which has a default property calledPathSeo
and two default methods using that property, and also they access theHttpContext
?Beta Was this translation helpful? Give feedback.
All reactions