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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pradeep ShetRank #595 · 4K reputationPosted Nov 13, 2014, 1:01 AM EST
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
MahaRank #2,573 · 543 reputationPosted Nov 13, 2014, 2:12 AM EST
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.
VulpesRank #55 · 29.2K reputationPosted Nov 13, 2014, 2:42 AM EST
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.
Daril148 reputationPosted Nov 17, 2021, 3:57 AM EST