Dynamic polymorphism using interfaces vs classes.

Imran Jalali 101 Reputation points
2023-04-09T00:51:38.7666667+00:00

Dear Friends, I am kind of novice in C# and just trying to clear my concepts. In C# we can achieve dynamic polymorphism using interfaces as well as using classes. What make it significant that we prefer to use one over the other one? In what type of situations we prefer to use interfaces over normal classes. I can fully understand that my question is quite basic but I need to understand with a practical example if possible or with some explanation. Thanks.

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Minxin Yu 13,506 Reputation points Microsoft External Staff
    2023-04-10T02:59:06.0766667+00:00

    Hi, Imran Jalali
    You could refer to the similar thread:Interface vs Abstract Class and Jay provided a simple example in answer.
    Pilot: abstract class C-141 Pilot: concrete class ISafety Officer: interface

    Abstract classes are used for Modelling a class hierarchy of similar looking classes Interface is used for Communication between 2 similar / non similar classes which does not care about type of the class implementing Interface

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.