Home TechnologyProgramming Subscribe to RSS

What Is Polymorphism And Virtual Functions In .NET Framework?

Polymorphism and Virtual Functions in .NET Framework.

Answer Question

1 Answer - Sort by: Date | Rating

    A while back I was writing a music system, and I decided that I wanted to be able to support both Win Amp and Windows Media Player as playback engines, but I didn't want all of my code to have to know which engine it was using. I therefore defined an abstract class, which is a class that defines the functions a derived class must implement, and that sometimes provides functions that are useful to both classes.

    In this case, the abstract class was called Music Server, and it had functions like Play (), Next Song (), Pause (), etc. All of the above functions were confirmed as abstract, so that each player class would have to apply those functions themselves. To make the application trouble-free and easy the polymorphisms and virtual functions have a vital role. Its now clear the role of polymorphisms.

    When there is a virtual function, the programmer can go by about an allusion to the abstract class slightly than the derived class, and the compiler will write code to call the suitable version of the function at runtime. In C# the polymorphisms and virtual functions have a good role which the programmers appreciate and enjoy this feature very much.
    0 0

    Rauf786  

    answered 3 years ago

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store

        Blurtit International