Polymorphism
-
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
-
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
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) -
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
Somewhat, but you're bogged down in details of implementation.
MUHAMMAD FAROOQ1991 wrote:
To resolve this problem
What problem?
-
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
-
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
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.
-
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.
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.
-
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.
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[^]
-
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[^]
Well, yes, but we no longer need a parent to define an interface (in some languages).
-
Well, yes, but we no longer need a parent to define an interface (in some languages).
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").
-
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.
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;
-
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").
But we no longer require a parent/child relationship in order to have different ("poly") behavior ("morphism") -- now unrelated classes can be used.
-
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;
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.