Hi All
Why we go for interface instead of abstract class?, why we go for explicit and implicit interface? because we can implement method with or without using that particular interface? thanks in advance
Hi All
Why we go for interface instead of abstract class?, why we go for explicit and implicit interface? because we can implement method with or without using that particular interface? thanks in advance
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
DarilPosted Nov 17, 2021, 8:57 AM
VulpesPosted Nov 13, 2014, 7:42 AM
1. Whilst you have to implement certain methods to satisfy the interface contract, you're not bothered about and don't really want the user to call them.
Explicit implementation means that the method doesn't have to be (and indeed can't be) declared public and it can only be called via an interface reference, not via a reference to the implementing class itself. This hides it from view somewhat.
2. A class is implementing two (or more interfaces) which have methods of the same name and you don't want these methods to share the same code. You can therefore implement one method implicitly and the other(s) explicitly.
MahaPosted Nov 13, 2014, 7:12 AM
First you must know the inheritance well. One parent class and many child classes inherited from its parent class are allowed in C#. Because one parent can have many child. This is a real world scenario.
C# will not allow a child class to inherit from many parent classes. Because this is not a real world scenario. In order to fulfill such a need Interfaces are playing a role.
Pradeep ShetPosted Nov 13, 2014, 6:01 AM
One reason for using the interface over abstract class is-
1) I cannot have multiple abstract class considered as base class but same is possible with interface.
Hope this answers your query