Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Polymorphism

Polymorphism

Scheduled Pinned Locked Moved C#
oophelpquestion
12 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M MUHAMMAD FAROOQ1991

    IS the complete defination for Polymorphism....? Polymorphism:- When child class inherits from a parent class and it gains all the method's properties of the parent class. To resolve this problem a class member from a parent class, the parent class has to be declare as virtual while the child class should declare as override.. this whole process is called polymorphism MUHAMMAD FAROOQ

    D Offline
    D Offline
    DaveyM69
    wrote on last edited by
    #2

    Read this page[^] from MS.

    Dave
    Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
    BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

    1 Reply Last reply
    0
    • M MUHAMMAD FAROOQ1991

      IS the complete defination for Polymorphism....? Polymorphism:- When child class inherits from a parent class and it gains all the method's properties of the parent class. To resolve this problem a class member from a parent class, the parent class has to be declare as virtual while the child class should declare as override.. this whole process is called polymorphism MUHAMMAD FAROOQ

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #3

      Somewhat, but you're bogged down in details of implementation.

      MUHAMMAD FAROOQ1991 wrote:

      To resolve this problem

      What problem?

      1 Reply Last reply
      0
      • M MUHAMMAD FAROOQ1991

        IS the complete defination for Polymorphism....? Polymorphism:- When child class inherits from a parent class and it gains all the method's properties of the parent class. To resolve this problem a class member from a parent class, the parent class has to be declare as virtual while the child class should declare as override.. this whole process is called polymorphism MUHAMMAD FAROOQ

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #4

        Try not to repost[^].

        Too much of heaven can bring you underground Heaven can always turn around Too much of heaven, our life is all hell bound Heaven, the kill that makes no sound

        1 Reply Last reply
        0
        • M MUHAMMAD FAROOQ1991

          IS the complete defination for Polymorphism....? Polymorphism:- When child class inherits from a parent class and it gains all the method's properties of the parent class. To resolve this problem a class member from a parent class, the parent class has to be declare as virtual while the child class should declare as override.. this whole process is called polymorphism MUHAMMAD FAROOQ

          A Offline
          A Offline
          Alan Balkany
          wrote on last edited by
          #5

          An essential feature of polymorphism is that the child classes exhibit different behaviors than the parent and sibling classes. This is implied by the name, which means "many shapes" in Latin.

          P 1 Reply Last reply
          0
          • A Alan Balkany

            An essential feature of polymorphism is that the child classes exhibit different behaviors than the parent and sibling classes. This is implied by the name, which means "many shapes" in Latin.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #6

            I don't think that "child ... parent and sibling classes" is strictly a part of polymorphism (at least not since we got interfaces); in my opinion they're really just one implementation.

            A M 2 Replies Last reply
            0
            • P PIEBALDconsult

              I don't think that "child ... parent and sibling classes" is strictly a part of polymorphism (at least not since we got interfaces); in my opinion they're really just one implementation.

              A Offline
              A Offline
              Alan Balkany
              wrote on last edited by
              #7

              The child classes are different implementations of the interface defined by the parent. See the Liskov Substitution Principle http://en.wikipedia.org/wiki/Liskov_substitution_principle[^]

              P 1 Reply Last reply
              0
              • A Alan Balkany

                The child classes are different implementations of the interface defined by the parent. See the Liskov Substitution Principle http://en.wikipedia.org/wiki/Liskov_substitution_principle[^]

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #8

                Well, yes, but we no longer need a parent to define an interface (in some languages).

                A 1 Reply Last reply
                0
                • P PIEBALDconsult

                  Well, yes, but we no longer need a parent to define an interface (in some languages).

                  A Offline
                  A Offline
                  Alan Balkany
                  wrote on last edited by
                  #9

                  The value of this arrangement is that the parent's interface is used by the users of these classes, so any child class can be substituted, and will provide different ("poly") behavior ("morphism").

                  P 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    I don't think that "child ... parent and sibling classes" is strictly a part of polymorphism (at least not since we got interfaces); in my opinion they're really just one implementation.

                    M Offline
                    M Offline
                    Michael J Eber
                    wrote on last edited by
                    #10

                    Well I think I would disagree with the statement of using Interfaces. In the truest, textbook usage of polymorphism your are providing a different implementation of an existing implementation. While an Interface defines necessary methods/properties that must be implemented, and you can have various implementations of those methods, you don't have a base behaviour to fall back on. So an example of Polymorphism would be a class that has a computation method that has been marked virtual. In the base class it uses all of the various properties within the class to compute a value. In addition to this computation method are a number of setters/validators that ensure all the data is valid before you call the method. There may also be some security wrapped around everything and it has all been tested and proven functional. You now need that class library to collect exactly the same data, and all validations, but you need to alter how the computation method behaves. So you inherit the base class and override the existing method to implement your behaviour. In a few months you may have another use of the same base class and in that case you want the base computation to occur, but you need to return half the value. In that case, once again, you inherit the base class, override the method, call the base computation and then return the value returned by 2. What you gain in the polymorphism model is all of the functionality of the base class that does NOT have to be tested (since it is already tested and working). All you have to test is your new computation code. Thus you gain functionality and minimize the testing needed to accomplish your goal.

                    Software Zen: delete this;

                    P 1 Reply Last reply
                    0
                    • A Alan Balkany

                      The value of this arrangement is that the parent's interface is used by the users of these classes, so any child class can be substituted, and will provide different ("poly") behavior ("morphism").

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #11

                      But we no longer require a parent/child relationship in order to have different ("poly") behavior ("morphism") -- now unrelated classes can be used.

                      1 Reply Last reply
                      0
                      • M Michael J Eber

                        Well I think I would disagree with the statement of using Interfaces. In the truest, textbook usage of polymorphism your are providing a different implementation of an existing implementation. While an Interface defines necessary methods/properties that must be implemented, and you can have various implementations of those methods, you don't have a base behaviour to fall back on. So an example of Polymorphism would be a class that has a computation method that has been marked virtual. In the base class it uses all of the various properties within the class to compute a value. In addition to this computation method are a number of setters/validators that ensure all the data is valid before you call the method. There may also be some security wrapped around everything and it has all been tested and proven functional. You now need that class library to collect exactly the same data, and all validations, but you need to alter how the computation method behaves. So you inherit the base class and override the existing method to implement your behaviour. In a few months you may have another use of the same base class and in that case you want the base computation to occur, but you need to return half the value. In that case, once again, you inherit the base class, override the method, call the base computation and then return the value returned by 2. What you gain in the polymorphism model is all of the functionality of the base class that does NOT have to be tested (since it is already tested and working). All you have to test is your new computation code. Thus you gain functionality and minimize the testing needed to accomplish your goal.

                        Software Zen: delete this;

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #12

                        Michael J. Eber wrote:

                        textbook usage

                        An outdated textbook, yes.

                        Michael J. Eber wrote:

                        method that has been marked virtual

                        That's just details of implementation and language.

                        Michael J. Eber wrote:

                        inherit the base class, override the method, call the base computation

                        That's details, and the caller doesn't need to know what's going on inside the class -- encapsulation.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups