Answer the question
In order to leave comments, you need to log in
What are the causes of interfaces in c#?
Hello everyone The
question is - why do we need interfaces in c#? If for the CLR these are some kind of abstract classes, and what is the point of them if everything that can be done with an interface can be done with an abstract class?
interesting to hear your opinion
Answer the question
In order to leave comments, you need to log in
en.wikipedia.org/wiki/Class_%28computer_programmin...
This should help to understand.
And
- not true. A class cannot inherit multiple abstract classes, but it can implement multiple interfaces. More precisely, it can inherit the hierarchy of abstract classes, but not several at the same time.
When creating C#, just like Java, the main task is to reduce the entry program, relative to C ++
One of the problems is multiple inheritance. The trouble is that in practice the inheritance tool is used as a code reuse tool, although it is not. In this case, with a rather branched design, the rhombus problem arises.
In diamond inheritance, there may be a situation where both parent classes have overridden a base interface method. And when, in turn, the programmer tries to use the class method using the same basic interface, he goes to hell.
In total, the issue that in the pros is solved in an organizational way in C # is solved technically.
In addition to multiple inheritance, interfaces allow you to create hierarchies for structures. In Sharp, structures are sealed (sealed), and therefore can only inherit from interfaces.
We can also make multiple interface implementations. Each implementation will contain its own logic, and then, where we need methods from the interface, we substitute the necessary implementation for a specific task.
This becomes especially clear when using dependency injection.
Most importantly, interfaces allow you to separate functionality from implementation. That is, unlike abstract classes that may contain some implementation in members, interfaces are bare functionality, read: just a set of methods and properties to access it, and that's it. No implementation. habrahabr.ru/post/30444
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question